0

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%')

Megan
  • 1,000
  • 1
  • 14
  • 44
  • Does this answer your question? [SQLAlchemy filter query "column LIKE ANY (array)"](https://stackoverflow.com/questions/28270708/sqlalchemy-filter-query-column-like-any-array) – roganjosh Feb 25 '20 at 16:59
  • @roganjosh I am already using this, but my issue is that when I print the compiled sql statement the array is NULL. Running the query works however ... – Megan Feb 25 '20 at 17:47

0 Answers0