I have to pass the result of my first redshift query to the second one. I am using postgres operator, Postgre script. doesn't have any return function as you see in this link
Actually I thought to modify the script and add return to the execute method. But the point is that I do not use the execute method and for executing the sql script I am using this:
retrieve_latest_query_task = PostgresOperator(
sql='rs_warm-up_query-id.sql',
postgres_conn_id='redshift',
task_id='retrieve_latest_query_ids_from_metadata'
)
Here are my two queries:
SELECT query
FROM (SELECT query,
querytxt,
ROW_NUMBER() OVER (PARTITION BY querytxt ORDER BY query ASC) AS num
FROM stl_query
WHERE userid = 102
AND starttime >= CURRENT_DATE - 2 + INTERVAL '7 hour'
AND starttime < CURRENT_DATE - 2 + INTERVAL '11 hour'
AND UPPER(querytxt) LIKE 'SELECT %'
ORDER BY query)
WHERE num = 1;
and with the retrieve data (which is a list) , I have to pass it to the second script:
SELECT LISTAGG(CASE WHEN LEN (RTRIM(TEXT)) = 0 THEN TEXT ELSE RTRIM(TEXT) END,'') within group(ORDER BY SEQUENCE) AS TEXT
FROM stl_querytext
WHERE query = {};
I thought that using xcom could be a good solution, as I don't return many rows. But I don't know how to use it with Postgres.
I don't want to use the temporal table, as I believe that for that small volume I don't need.
I ll appreciate your help.