M
M
Maxim Tarabrin2018-04-12 18:05:12
PostgreSQL
Maxim Tarabrin, 2018-04-12 18:05:12

Why is there an error when passing a tuple of 1 element to a sql query?

Dear developers, the question arose why an exception is generated when passing a tuple to a SQL query:

psycopg2.ProgrammingError: syntax error at or near ")"
LINE 7: ...roduct='T' and c.status='A' ORDER BY c.id in (194,) DESC,c.c...


If there are 2 or more ids in the tuple, then everything is fine, otherwise it writes a comma at the end, as a result of which the request does not pass. But how do you wrap your lists in a tuple for a sql query?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2018-04-12
@melkij

Because syntactically there can't be a comma.
If you put a comma - make sure that it is not there.
If your ORM or other library code puts a comma, then either you are using the library incorrectly or this is a bug in this library.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question