psycopg2.errors.SyntaxError: syntax error at or near "["

773 views Asked by At

I am trying to execute simple query using sqlalchemy that basically just uses the IN clause in sql

Below is the query

select(Model).where(Model.column_name.in_(["test", "test1"]))

Below is the error i get

psycopg2.errors.SyntaxError: syntax error at or near "["
LINE 3: WHERE table_name.column_name IN ([POSTCOMPILE_column_name_1])
2

There are 2 answers

0
ALTAF HUSSAIN On

I was using aiopg==0.16.0 but after upgradation to aiopg==1.3.3 everything is working fine.

3
Ashkan Goleh Pour On

by orm

session.query(MODEL).filter(MODEL.col_name.in_((1,100))).all()

plain row:

session.execute(
    select(
        [MODEL.c.id, MODEL.c.name], 
        MODEL.c.id.in_((1, 100))
    )
).fetchall()