Skip to content

Commit 95f921e

Browse files
committed
Improved trigger query for PG 9.5
Former-commit-id: 9dd548f
1 parent 6ee6b02 commit 95f921e

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

trigger.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,13 @@ func (c TriggerSchema) Change(obj interface{}) {
105105
// compareTriggers outputs SQL to make the triggers match between DBs
106106
func compareTriggers(conn1 *sql.DB, conn2 *sql.DB) {
107107
sql := `
108-
SELECT tbl.nspname || '.' || tbl.relname AS table_name
109-
, t.tgname AS trigger_name
110-
, pg_catalog.pg_get_triggerdef(t.oid, true) AS definition
111-
, t.tgenabled AS enabled
108+
SELECT n.nspname || '.' || c.relname AS table_name
109+
, t.tgname AS trigger_name
110+
, pg_catalog.pg_get_triggerdef(t.oid, true) AS definition
111+
, t.tgenabled AS enabled
112112
FROM pg_catalog.pg_trigger t
113-
INNER JOIN (
114-
SELECT c.oid, n.nspname, c.relname
115-
FROM pg_catalog.pg_class c
116-
JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace AND n.nspname NOT LIKE 'pg_%')
117-
WHERE pg_catalog.pg_table_is_visible(c.oid)) AS tbl
118-
ON (tbl.oid = t.tgrelid)
119-
AND NOT t.tgisinternal
120-
ORDER BY 1;
113+
INNER JOIN pg_catalog.pg_class c ON (c.oid = t.tgrelid)
114+
INNER JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace AND n.nspname NOT LIKE 'pg_%');
121115
`
122116

123117
rowChan1, _ := pgutil.QueryStrings(conn1, sql)

0 commit comments

Comments
 (0)