Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the conversion of list or tuple args to SQL. #36

Merged
merged 3 commits into from
Nov 21, 2013

Conversation

gbandet
Copy link
Contributor

@gbandet gbandet commented Nov 4, 2013

When making a query with an argument which is a one element list (or tuple) for an IN clause, the generated SQL is not valid and the query fails.

Examples:

  • c.execute("SELECT * from T WHERE id IN %s", [[1, 2, 3]]) --> SELECT * from T WHERE id IN ('1', '2', '3') OK
  • c.execute("SELECT * from T WHERE id IN %s", [[1]]) --> SELECT * from T WHERE id IN ('1',) Fail
  • c.execute("SELECT * from T WHERE id IN %(list)s", {'list': [1, 2, 3]}) --> SELECT * from T WHERE id IN ('1', '2', '3') OK
  • c.execute("SELECT * from T WHERE id IN %(list)s", {'list': [1]}) --> SELECT * from T WHERE id IN ('1',) Fail

In fact the list is converted as the string representation of a python tuple, with a final coma for one element tuples, and then breaks the SQL syntax.

When there is one element on the list, the generated SQL was
(1,) (python notation of a single element tuple, which is not
valid in SQL.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants