In using Python with a connection to a PostgreSQL database, we are using SQLAlchemy, but not the ORM. We have a table where one of the columns is an array of strings, and we want to retrieve all the rows for which an input parameter is NOT present in the array column. Please do note that we can retrieve the results of other queries for SQLAlchemy, so the problem has to be in the query creation.
The SQL we need to implement looks like this:
select pk from table where 'paramstring' NOT IN(array_column);
-- returns several rows
The function that we have come up with in Python is like this:
def get_not_matching(param):
select_statement = select([the_table.c.pk]).where(
~data_table.c.array_column.in_([param])
)
#... execute and retrieve ResultProxy
# the result_set comes back empty
Any suggestions would be greatly appreciated.