You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Copy/paste of the `#foreign_keys(table)` method adapted to return every single
83
+
# foreign key in the database.
84
+
defall_foreign_keys
85
+
fk_info=internal_exec_query(<<~SQL,"SCHEMA")
86
+
SELECT CASE
87
+
WHEN n1.nspname = current_schema()
88
+
THEN ''
89
+
ELSE n1.nspname || '.'
90
+
END || t1.relname AS from_table,
91
+
CASE
92
+
WHEN n2.nspname = current_schema()
93
+
THEN ''
94
+
ELSE n2.nspname || '.'
95
+
END || t2.relname AS to_table,
96
+
a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete, c.convalidated AS valid, c.condeferrable AS deferrable, c.condeferred AS deferred,
97
+
c.conkey, c.confkey, c.conrelid, c.confrelid
98
+
FROM pg_constraint c
99
+
JOIN pg_class t1 ON c.conrelid = t1.oid
100
+
JOIN pg_class t2 ON c.confrelid = t2.oid
101
+
JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid
102
+
JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid
0 commit comments