How to search for array in postgres through sqlalchemy?

Asked

Viewed 33 times

0

My database has a column like ARRAY(sa.BIGINT). My intention is to use the command filter_byof sqlalchemy to search for an element that has the list_secao_id field equal to [58,45,12], for example:

instance = session.query(model).filter_by(**{'list_secao_id': [58,45,12]}).first()

However, I am getting the following error message:

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedFunction) operator does not exist: bigint[] = integer[]

LINE 3: ...corte.recorte_ordem = 1 AND recorte.list_secao_id = ARRAY[58...

HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.

I tried to direct the cast, but I was unsuccessful:

from sqlalchemy.types import ARRAY

instance = session.query(model).filter_by(**{'list_secao_id': ARRAY([58,45,12])}).first()

Error:

Object has no attribute self_group

How can I change my query in order to get successful searching by list?

  • Which DBAPI are you using? psycopg2?

  • That, psycopg2 is dbapi

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.