Skip to content
Browse files

Merge pull request #36021 from qgis-bot/backport-35983-to-release-3_12

[Backport release-3_12] Handle CONSTRAINT TRIGGER on DB Manager/PostgreSQL.
  • Loading branch information
m-kuhn committed Apr 27, 2020
2 parents bd4173f + 373e1cf commit fc2cb76c7debe4e1fa1f2863593550397ef76f62
Showing with 4 additions and 1 deletion.
  1. +4 −1 python/plugins/db_manager/db_plugins/postgis/
@@ -652,12 +652,15 @@ def getTableConstraints(self, table):
version_number = int(self.getInfo()[0].split(' ')[1].split('.')[0])
con_col_name = 'consrc' if version_number < 12 else 'conbin'

# In the query below, we exclude rows where pg_constraint.contype whose values are equal to 't'
# because 't' describes a CONSTRAINT TRIGGER, which is not really a constraint in the traditional
# sense, but a special type of trigger, and an extension to the SQL standard.
sql = u"""SELECT c.conname, c.contype, c.condeferrable, c.condeferred, array_to_string(c.conkey, ' '), c.%s,
t2.relname, c.confupdtype, c.confdeltype, c.confmatchtype, array_to_string(c.confkey, ' ') FROM pg_constraint c
LEFT JOIN pg_class t ON c.conrelid = t.oid
LEFT JOIN pg_class t2 ON c.confrelid = t2.oid
JOIN pg_namespace nsp ON t.relnamespace = nsp.oid
WHERE t.relname = %s %s """ % (con_col_name, self.quoteString(tablename), schema_where)
WHERE c.contype <> 't' AND t.relname = %s %s """ % (con_col_name, self.quoteString(tablename), schema_where)

c = self._execute(None, sql)
res = self._fetchall(c)

0 comments on commit fc2cb76

Please sign in to comment.
You can’t perform that action at this time.