Skip to content
Permalink
Browse files

Handle CONSTRAINT TRIGGER on DB Manager/PostgreSQL.

  • Loading branch information
github-actions authored and nyalldawson committed Apr 27, 2020
1 parent 1ddc74a commit 77bb13a283429bf503adcb332946469ea8a0a2d5
Showing with 4 additions and 1 deletion.
  1. +4 −1 python/plugins/db_manager/db_plugins/postgis/connector.py
@@ -540,12 +540,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 77bb13a

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