Skip to content

Commit

Permalink
Handle CONSTRAINT TRIGGER on DB Manager/PostgreSQL.
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Apr 27, 2020
1 parent 37aab82 commit 373e1cf
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion python/plugins/db_manager/db_plugins/postgis/connector.py
Expand Up @@ -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)
Expand Down

0 comments on commit 373e1cf

Please sign in to comment.