Merge pull request #35983 from espinafre/dbmanager_pgsql_constraint_trigger

Handle CONSTRAINT TRIGGER on DB Manager/PostgreSQL.
This commit is contained in:
Matthias Kuhn 2020-04-27 08:01:22 +02:00 committed by GitHub
commit d62c982b6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -652,12 +652,15 @@ class PostGisDBConnector(DBConnector):
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)