Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psqldef syntax error on REFERENCES table (field) FK constraint #84

Closed
AriaFallah opened this issue Dec 7, 2020 · 2 comments
Closed

Comments

@AriaFallah
Copy link

AriaFallah commented Dec 7, 2020

Problem

I can't define foreign key relationships using REFERENCES on specific fields because I get

found syntax error when parsing DDL "CREATE TABLE b (
  b_id INTEGER PRIMARY KEY,
  a_id INTEGER REFERENCES a (a_id),
  a_my_text TEXT NOT NULL REFERENCES a (my_text)
)": syntax error at position 75

Running the same code directly in psql works though! I'm using the following command to run psqldef

PGSSLMODE=disable psqldef -h localhost -U postgres -W verysecure postgres --dry-run < ./db/schema.sql

You can find the full grammar here https://www.postgresql.org/docs/9.1/sql-createtable.html if you CTRL-F for "REFERENCES reftable"

Expected

Initial schema

Blank!

Input DDLs

CREATE TABLE a (
  a_id INTEGER PRIMARY KEY,
  my_text TEXT UNIQUE NOT NULL
);

CREATE TABLE b (
  b_id INTEGER PRIMARY KEY,
  a_id INTEGER REFERENCES a (a_id),
  a_my_text TEXT NOT NULL REFERENCES a (my_text)
);

Output DDLs

None 😢

@k0kubun k0kubun closed this as completed in 02ee350 Dec 7, 2020
@k0kubun
Copy link
Collaborator

k0kubun commented Dec 7, 2020

👍 Fixed the parser and started releasing v0.8.4.

@AriaFallah
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants