Asyncpg: accept list or tuple parameter for the "WHERE file IN (values)" clause

Created on 20 Jul 2017  路  3Comments  路  Source: MagicStack/asyncpg

When executing :
await conn.fetch("SELECT * FROM table WHERE field IN ($1)", tuple_parameter)
Let say that field is an integer field.
It complains that the parameter type is "tuple" instead of "int".
Ty

Most helpful comment

Hello,
thank you for your answer. I've tested your suggested solution and it
works :)
nonetheless, the clause "filed IN (values)" seems valid in Postgresql :
cf 搂9.23.1 in
https://www.postgresql.org/docs/9.5/static/functions-comparisons.html
furthermore, before unsing asyncpg, I used psycopg2 + aiopg and I used
the in_ operator provided by SqlAlchemy. The query converted to str
contained the 'IN'.
anyway, I got a solution and that's the best.
Franck

On 2017-07-20 14:50, Yury Selivanov wrote:

https://magicstack.github.io/asyncpg/current/faq.html [1]

--
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub [2], or mute the
thread [3].

*

Links:

[1] https://magicstack.github.io/asyncpg/current/faq.html
[2]
https://github.com/MagicStack/asyncpg/issues/175#issuecomment-316692683
[3]
https://github.com/notifications/unsubscribe-auth/AB0GtawOJ1vj3-zsSYotH43OUAJ4UMFqks5sP0z6gaJpZM4OeC04

All 3 comments

Hello,
thank you for your answer. I've tested your suggested solution and it
works :)
nonetheless, the clause "filed IN (values)" seems valid in Postgresql :
cf 搂9.23.1 in
https://www.postgresql.org/docs/9.5/static/functions-comparisons.html
furthermore, before unsing asyncpg, I used psycopg2 + aiopg and I used
the in_ operator provided by SqlAlchemy. The query converted to str
contained the 'IN'.
anyway, I got a solution and that's the best.
Franck

On 2017-07-20 14:50, Yury Selivanov wrote:

https://magicstack.github.io/asyncpg/current/faq.html [1]

--
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub [2], or mute the
thread [3].

*

Links:

[1] https://magicstack.github.io/asyncpg/current/faq.html
[2]
https://github.com/MagicStack/asyncpg/issues/175#issuecomment-316692683
[3]
https://github.com/notifications/unsubscribe-auth/AB0GtawOJ1vj3-zsSYotH43OUAJ4UMFqks5sP0z6gaJpZM4OeC04

For people reading this issue too quickly like me: what's invalid is not expression in (values), but expression in $1, where $1 is a native var.

Was this page helpful?
0 / 5 - 0 ratings