Skip to content

FK column from referencing table not present in "references" but present in "alter" #196

@tduval-unifylogic

Description

@tduval-unifylogic

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):

  1. 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))
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions