sqlparse icon indicating copy to clipboard operation
sqlparse copied to clipboard

sqlparse format using strip_comments=True not working with redshift unload command

Open Hariomsingh2007 opened this issue 4 years ago • 0 comments

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;

Hariomsingh2007 avatar Mar 15 '22 16:03 Hariomsingh2007