1

I want to use python to execute a CREATE STATEMENT clause, specifying default values for certain columns using parameter substitution with ? (so that I can safely specify defaults from python types).

It doesn't appear to work, although it works fine when I use parametric statements in a select or similar statement. For example:

As expected:

>>> list(sqlite3.connect('sensemap.sql3').cursor().execute('select ?', (101,)))
[(101,)]

Unexpected:

>>> sqlite3.connect('sensemap.sql3').cursor().execute('create table mytable (mycolumn default ?)', (101,))
Traceback (most recent call last):
  File "<console>", line 1, in <module>
OperationalError: near "?": syntax error

Why is that? Is what I'm attempting possible?

1 Answer 1

1

The original SQL statements of all your schema objects are stored in the database (try SELECT sql FROM sqlite_master). With such a simple text value, it is not possible to remember parameter values, so parameters are not allowed in CREATE xxx statements.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.