When using Python with a connection to a PostgreSQL database, we use SQLAlchemy, but not ORM. We have a table in which one of the columns is an array of rows, and we want to get all rows for which the input parameter is NOT present in the column of the array. Please note that we can get the results of other queries for SQLAlchemy, so the problem should be creating a query.
The SQL we need to implement is as follows:
select pk from table where 'paramstring' NOT IN(array_column);
The function we created in Python is as follows:
def get_not_matching(param): select_statement = select([the_table.c.pk]).where( ~data_table.c.array_column.in_([param]) )
Any suggestions are welcome.
source share