summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/psycopg2.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/psycopg2.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/psycopg2.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py
index 2446604ba..72c36b4a8 100644
--- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py
+++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py
@@ -644,7 +644,14 @@ class PGExecutionContext_psycopg2(PGExecutionContext):
class PGCompiler_psycopg2(PGCompiler):
- pass
+ def bindparam_string(self, name, **kw):
+ if "%" in name and not kw.get("post_compile", False):
+ # psycopg2 will not allow a percent sign in a
+ # pyformat parameter name even if it is doubled
+ kw["escaped_from"] = name
+ name = name.replace("%", "P")
+
+ return PGCompiler.bindparam_string(self, name, **kw)
class PGIdentifierPreparer_psycopg2(PGIdentifierPreparer):