I've got a sql query where I'm using the sqlalchemy text function because I have a rather long and complicated query. I'd like to keep this discussion to bits about how I can handle it using compositional sql, unless its for some reason unsolvable that way.
right now, one of my subqueries uses a syntax like this
select *
from table_a
join table_b on table_a.b_id = table_b.id
join table_c on table_c.b_id = table_b.id
where table_a.timestamp BETWEEN to_date(:time_range_start,'yyyy-mm-dd HH24:MI:SS'::text) and to_date(:time_range_end,'yyyy-mm-dd HH24:MI:SS'::text)
AND table_a.id = ANY(:a_ids)
AND table_a.attribute_id = ANY(:attribute_ids)
AND table_b.id = ANY(:b_ids)
So what I need to understand is either 1. A default value to give to the ANY() function so that it essentially makes it not filter 2. A way to conditionally format in that portion of the query into the text
I could potentially just use a python string format before calling the text() function on it?