summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-07-12 18:19:08 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-07-13 10:15:07 -0400
commit0e46359cb00b453448e37ec16fce744f73c98581 (patch)
tree1be1d75ff64887dc134a9b424c154339b95ba862 /lib/sqlalchemy/dialects/postgresql
parentca52e87268fec966f6005b1e4aa30206ae895e9e (diff)
downloadsqlalchemy-0e46359cb00b453448e37ec16fce744f73c98581.tar.gz
Extract format_constraint truncation rules to ON CONFLICT
Fixed issue where a too-long constraint name rendered as part of the "ON CONFLICT ON CONSTRAINT" element of the :class:`_postgresql.Insert` construct due to naming convention generation would not correctly truncate the name in the same way that it normally renders within a CREATE TABLE statement, thus producing a non-matching and too-long constraint name. Fixes: #6755 Change-Id: Ib27014a5ecbc9cd5861a396f8bb49fbc60bf49fe
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index ea2eda902..48fc4fd71 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -2322,8 +2322,16 @@ class PGCompiler(compiler.SQLCompiler):
def _on_conflict_target(self, clause, **kw):
if clause.constraint_target is not None:
- target_text = "ON CONSTRAINT %s" % self.preparer.quote(
- clause.constraint_target
+ # target may be a name of an Index, UniqueConstraint or
+ # ExcludeConstraint. While there is a separate
+ # "max_identifier_length" for indexes, PostgreSQL uses the same
+ # length for all objects so we can use
+ # truncate_and_render_constraint_name
+ target_text = (
+ "ON CONSTRAINT %s"
+ % self.preparer.truncate_and_render_constraint_name(
+ clause.constraint_target
+ )
)
elif clause.inferred_target_elements is not None:
target_text = "(%s)" % ", ".join(