simple-ddl-parser
simple-ddl-parser copied to clipboard
FK column from referencing table not present in "references" but present in "alter"
Describe the bug
when a foreign key is defined within CREATE TABLE tablename ():
CONSTRAINT fk_order FOREIGN KEY (order_identifier) REFERENCES orders(order_id),
The column order_identifier is not output in the results, so no way to know which column from the table is the referencing column. e.g., output:
"references": [
{
"table": "orders",
"columns": [
"order_id"
],
"schema": null,
"on_delete": null,
"on_update": null,
"deferrable_initially": null,
"constraint_name": "fk_order"
}
]
To Reproduce Steps to reproduce the behavior (this example is using postgres as dialect):
- process file1.sql and view results and find alter in order_items table results. Column "name": "order_identifier" is present
sql = open('file1.sql', 'r').read()
results = parse_from_file(sql, group_by_type=True)
print(json.dumps(results, indent=2))
- process file2.sql and find constraints/references in order_items table results. Column "name": "order_identifier" is not present
sql = open('file2.sql', 'r').read()
results = parse_from_file(sql, group_by_type=True)
print(json.dumps(results, indent=2))
Expected behavior to see similar results output from alter, where the name of referencing column is presented:
"alter": {
"columns": [
{
"name": "order_identifier",
"constraint_name": "fk_order",
"references": {
"table": "orders",
"schema": null,
"on_delete": null,
"on_update": null,
"deferrable_initially": null,
"column": "product_id"
}
}, ...
Screenshots n/a
Desktop (please complete the following information):
- OS: macOS Monterey v12.6.1, Mac mini (M1, 2020)
- Browser: n/a
- Version:
- python == 3.9.6
- simple-ddl-parser == 0.30.0
Smartphone (please complete the following information):
- Device: n/a
- OS: n/a
- Browser: n/a
- Version: n/a
Additional context Add any other context about the problem here.
@xnuinside , checking in... would really like to use your parser as it is amazing! The referencing column metadata missing is a blocker for us though. Any idea on when this could get resolved?
@tduval-unifylogic hi! I will have time on this weekends, I hope, I will create new release with fix
Thank you! Access to parsed comments would also be a blessing! I know there's an issue captured on this already. We're creating ontologies from schemas, so any semantic context we can get is a bonus.
sure, I will try to add it
I am having the same problem. Will try and post a PR in the next couple of days.
I don't have the ability to update ticket status, but I believe that as of version 0.32.0 this should be solved.