I need to dynamically compile a SQL query.
SELECT s.* , ARRAY( SELECT stt.tag_id FROM subscriber_to_tag stt WHERE stt.channel_id = s.channel_id stt.subscriber_id = s.subscriber_id ) as test FROM s WHERE 1 in test AND 2 in test AND 3 in test The request gives an error
ERROR: syntax error at or near "test" LINE 2: ... s.subscriber_id) as test FROM subscribers s WHERE 1 in test There may be many of these numbers, 1,2,3, and, in order not to make select all the time, I want to save it to a variable and check the occurrence.
Any idea how to do this smartly?