-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3650 from tp-woven/talp/issue-3646
add test reproducing #3646
- Loading branch information
Showing
3 changed files
with
116 additions
and
72 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
diesel_cli/src/infer_schema_internals/load_foreign_keys.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
SELECT | ||
sch.nspname AS "self_schema", | ||
tbl.relname AS "self_table", | ||
ARRAY_AGG(col.attname ORDER BY u.attposition) AS "self_columns", | ||
f_sch.nspname AS "foreign_schema", | ||
f_tbl.relname AS "foreign_table", | ||
ARRAY_AGG(f_col.attname ORDER BY f_u.attposition) AS "foreign_columns" | ||
FROM pg_constraint c | ||
LEFT JOIN LATERAL UNNEST(c.conkey) WITH ORDINALITY AS u(attnum, attposition) ON TRUE | ||
LEFT JOIN LATERAL UNNEST(c.confkey) WITH ORDINALITY AS f_u(attnum, attposition) ON f_u.attposition = u.attposition | ||
JOIN pg_class tbl ON tbl.oid = c.conrelid | ||
JOIN pg_namespace sch ON sch.oid = tbl.relnamespace | ||
LEFT JOIN pg_attribute col ON (col.attrelid = tbl.oid AND col.attnum = u.attnum) | ||
LEFT JOIN pg_class f_tbl ON f_tbl.oid = c.confrelid | ||
LEFT JOIN pg_namespace f_sch ON f_sch.oid = f_tbl.relnamespace | ||
LEFT JOIN pg_attribute f_col ON (f_col.attrelid = f_tbl.oid AND f_col.attnum = f_u.attnum) | ||
WHERE sch.nspname = $1 and f_sch.nspname = $1 and c.contype = 'f' | ||
GROUP BY "self_schema", "self_table", "foreign_schema", "foreign_table" | ||
ORDER BY "self_schema", "self_table"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters