I am trying to see the compiled version of my sqlalchemy select object. At one point I need to see if a varchar[]
column contains any string from a list of sub strings. (Other parts of my query where I am using in_ and a list of strings are working.) Why is this printing:
... <BEGINNING OF QUERY> ... LIKE ANY(NULL)
instead of
... <BEGINNING OF QUERY> ... LIKE ANY('list%', 'of%', 'substrings%')
Note (Other parts of my query where I am using in_ and a list of strings are working.)
from custom_database_classes import MyTable
from sqlalchemy import create_engine, select, cast, func, or_, and_, any_,
def read_data():
array_q = func.lower(func.array_to_string(MyTable.some_arr_col, ' ')).like(any_(['list%', 'of%', 'substrings%']))
query = select(['*']).where(or_(array_q))
print(query.compile(compile_kwargs={"literal_binds": True}))
Actual Result
SELECT * FROM Schema.MyTable
WHERE lower(array_to_string(Schema.MyTable.some_arr_col, ' ')) LIKE ANY (NULL)
Expected Result
SELECT * FROM Schema.MyTable
WHERE lower(array_to_string(Schema.MyTable.some_arr_col, ' ')) LIKE ANY ('list%', 'of%', 'substrings%')