Skip to content

Commit 15642f9

Browse files
committed
sub select is literal and escaped
1 parent 6448366 commit 15642f9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

redshift_sqlalchemy/dialect.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from sqlalchemy.types import VARCHAR, NullType
55
from sqlalchemy.ext.compiler import compiles
66
from sqlalchemy.sql.expression import Executable, ClauseElement
7+
from sqlalchemy.sql.expression import BindParameter
78

89

910
class RedshiftDialect(PGDialect_psycopg2):
@@ -80,10 +81,19 @@ def visit_unload_from_select(element, compiler, **kw):
8081
''' Returns the actual sql query for the UnloadFromSelect class
8182
'''
8283
return "unload ('%(query)s') to '%(bucket)s' credentials 'aws_access_key_id=%(access_key)s;aws_secret_access_key=%(secret_key)s' delimiter ',' addquotes" % {
83-
'query': compiler.process(element.select),
84+
'query': compiler.process(element.select, unload_select=True, literal_binds=True),
8485
'bucket': element.bucket,
8586
'access_key': element.access_key,
8687
'secret_key': element.secret_key,
8788
}
8889

89-
90+
@compiles(BindParameter)
91+
def visit_bindparam(bindparam, compiler, **kw):
92+
#print bindparam
93+
res = compiler.visit_bindparam(bindparam, **kw)
94+
if 'unload_select' in kw:
95+
#process param and return
96+
res = res.replace("'", "\\'")
97+
return res
98+
else:
99+
return res

0 commit comments

Comments
 (0)