As @hoodahelll mentioned, you can get the actual query text with parameters replaced with actual values from STL_QUERYTEXT
. However, STL_QUERYTEXT
has the query text broken into 200 byte chunks.
You can use the following SQL to get information about queries as well as the full SQL text, as long as it the entire query is less than the max VARCHAR size in Redshift (65535 bytes):
SELECT
DISTINCT
sq.xid,
sq.pid,
sq.query AS query_id,
sq.starttime AS start_time,
sq.endtime AS end_time,
-- this works as long as the total query size isn't > 65535 bytes:
LISTAGG(sqt.text, '') WITHIN GROUP (ORDER BY sqt.sequence)
OVER (PARTITION BY sqt.xid, sqt.pid, sqt.query) AS query_text
FROM
STL_QUERY sq
JOIN STL_QUERYTEXT sqt ON
sq.xid = sqt.xid AND sq.pid = sqt.pid AND sq.query = sqt.query
WHERE
<INSERT WHERE CLAUSE HERE>