Skip to content

Commit 9ff2066

Browse files
committed
bug: Support Retrieval of Cross-Schema Foreign Keys
Allow `get_multi_foreign_keys` to retrieve foreign keys between tables in different schemas. The current SQL used to retrieve them has a mistake in the JOINs used to retrieve them, confusing the `table_schema` column and the `constraint_schema` column. This goes unnoticed as long as everything is in the same schema. fixes: #638
1 parent 5077ddb commit 9ff2066

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,10 +1472,12 @@ def get_multi_foreign_keys(
14721472
)
14731473
FROM information_schema.table_constraints AS tc
14741474
JOIN information_schema.constraint_column_usage AS ccu
1475-
USING (table_catalog, table_schema, constraint_name)
1475+
ON ccu.table_catalog = tc.table_catalog
1476+
and ccu.constraint_schema = tc.table_schema
1477+
and ccu.constraint_name = tc.constraint_name
14761478
JOIN information_schema.constraint_table_usage AS ctu
14771479
ON ctu.table_catalog = tc.table_catalog
1478-
and ctu.table_schema = tc.table_schema
1480+
and ctu.constraint_schema = tc.table_schema
14791481
and ctu.constraint_name = tc.constraint_name
14801482
JOIN information_schema.key_column_usage AS kcu
14811483
ON kcu.table_catalog = tc.table_catalog

0 commit comments

Comments
 (0)