Open matndev opened 1 year ago
I can solve this issue. Please assign this bug to me.
@Bidhu1024 can u please update if not can i work on this @mathiasrw
can i have the documentation for it @mathiasrw
SELECT
ccu.table_name AS table_name,
ccu.column_name AS column_name,
ccu.constraint_name AS constraint_name,
ccu.referenced_table_name AS referenced_table_name,
ccu.referenced_column_name AS referenced_column_name
FROM
information_schema.key_column_usage AS kcu
JOIN
information_schema.constraint_column_usage AS ccu
ON ccu.constraint_name = kcu.constraint_name
WHERE
kcu.constraint_schema = 'your_schema'
AND ccu.table_name = 'Table2'
AND ccu.column_name = 'Column1';
@mathiasrw try this it will retrieve the information regarding the foreign keys
@mathiasrw could u try this
Looks correct to me. @matndev Does this work?
@matndev can u update?
@matndev any updates
Tried today, returns me undefined when executing SELECT in console.log. But I would rather access fk within tables object.
alasql@4:119 Uncaught TypeError: Cannot read properties of undefined (reading 'tables') at alasql@4:119:13221 at Array.forEach (
) at S.Select.compileDefCols (alasql@4:119:13096) at S.Select.compile (alasql@4:49:11442) at u.dexec (alasql@4:38:2105) at u.exec (alasql@4:38:1789) at u (alasql@4:31:907)
@DarrenDsouza7273 do you know a different way to retrieve the foreign keys from a table? I tried your solution and I got the same error as @matndev. Such as they mentioned, I would also prefer to retrieve this information from the tables object, and I'm up to make a PR for it even 🙂
I'm having an issue with foreign key detection. I'm creating two tables, let's call them "Table1" and "Table2". Table1 has a primary key called "PK_Table1" on a column named "Column1". Table2 has a foreign key "FK_Table2_Column1" that references "Column1" in "Table1".
When I create the tables and inspect the resulting objects, "Table1" correctly shows "Column1" as having a primary key, but "Table2" does not show "Column1" as having a foreign key. Additionally, when I try to access the "foreignkey" property of "Column1" in "Table2", it doesn't exist.
I've checked the "checks" property of "Table2", and the foreign key constraint appears to be correctly detected and stored there (fk is equal to true and the name of the foreign key is printed, but not the columnid).
Could you please advise on how to properly detect and access foreign keys?
JSFiddle: https://jsfiddle.net/rcnv6gfs/