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

Time:06-02

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])

CodePudding user response:

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()

CodePudding user response:

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

  • Related