sqlparse
sqlparse copied to clipboard
sqlparse format using strip_comments=True not working with redshift unload command
import sqlparse
rawsql="""
UNLOAD (
$$
WITH evt_tmp AS
(
SELECT col1,
col2,
col3
FROM emp e
WHERE emp_id = 123
AND job_id is not null
-- AND job_role_id not in (1,2,3) -- this is not getting stripped out
AND location='BLR'
$$
)
to 's3://bucket/'
iam_role 'arn:aws:iam::XXXXXXX:role/XXXX'
delimiter as ' '
allowoverwrite
gzip;
"""
sql= sqlparse.format(rawsql, strip_comments=True).strip()
print(sql)
output:
UNLOAD (
$$
WITH evt_tmp AS
(
SELECT col1,
col2,
col3
FROM emp e
WHERE emp_id = 123
AND job_id is not null
-- AND job_role_id not in 1,2,3) -- this is not getting stripped out
AND location='BLR'
$$
)
to 's3://bucket/'
iam_role 'arn:aws:iam::XXXXXXX:role/XXXX'
delimiter as ' '
allowoverwrite
gzip;