Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7845355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:11:48+00:00 2026-06-02T17:11:48+00:00

I want to execute an SQL statement like this: SELECT * FROM table WHERE

  • 0

I want to execute an SQL statement like this:

SELECT * FROM table WHERE spam LIKE ? AND eggs LIKE :eggs

Python sqlite3 module documentation says:

Cursor.execute(sql[, parameters])

[…]

The sqlite3 module supports two kinds of placeholders: question marks (qmark style) and named placeholders (named style).

But is there a way to use both qmark style and named style?

SOLUTION (thanks to jadkik94):

params = ["a","b","c"]
kparams = {'d':"d", 'e':"e"}
sql = "SELECT * FROM table WHERE (a LIKE ? OR b LIKE ? OR c LIKE ?) AND (d LIKE :d AND e LIKE :e)"
sql = sql.replace("?", ":{}").format(*range(sql.count("?")))
# >>> sql
# "SELECT * FROM table WHERE (a like :0 OR b like :1 OR c like :2) AND (d like :d AND e like :e)"
kparams.update(dict(map(lambda x: (str(x[0]), x[1]), enumerate(params))))
# >>> kparams
# {'0': 'a', '1': 'b', '2': 'c', 'd': 'd', 'e': 'e'}
c.execute(sql, kparams)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:11:49+00:00Added an answer on June 2, 2026 at 5:11 pm

    If this is your code:

    known = {'d': 'dval', 'e': 'eval'}
    unknown = ['a', 'b', 'c']
    # instead of
    "SELECT * FROM table WHERE (a like ? OR b like ? OR c like ?) AND (d like :d AND e like :e)"
    known.update(dict((str(i), v) for i, v in enumerate(unknown)))
    # and use
    "SELECT * FROM table WHERE (a like :1 OR b like :2 OR c like :3) AND (d like :d AND e like :e)"
    

    I guess you cannot use both ways together, but that’s one alternative.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL Statement that works as I want. select COUNT(*), MIN(emailed_to)from email.email_archive
I'd like to know if it's possible to execute more than one SQL statement
i want use single quotations inside a transact sql statement, then execute that statement.
I simply want to execute the following Mysql statement SET @a = 1;SELECT @a;
Example--- Like for SQL we write SQL statement as String and then we execute
Using SQL 2005: Taking too much time to execute I want to filter the
I want to execute some Python code, typed at runtime, so I get the
I want to execute this script (view source) that uses Google Translate AJAX API
I want to execute a batch file from a java program. I am using
It looks like #temptables created using dynamic SQL via the EXECUTE string method have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.