drawdb icon indicating copy to clipboard operation
drawdb copied to clipboard

[BUG] Importing SQL (PostgreSQL) with Foreign Key reference does cause a SyntaxError

Open emschu opened this issue 1 month ago • 2 comments

Describe the bug Importing the provided test SQL (in PostgreSQL dialect) does not work and fails with a false-positive SyntaxError. The given test SQL is valid in Postgres dialect.

To Reproduce Steps to reproduce the behavior:

  1. Open the application
  2. Click on "File" -> "Import from SQL"
  3. Import an .sql-file with the test content below
  4. See error: "SyntaxError [Ln 13, Col 1]: Expected "(", "--", ".", "/*", or [ \t\n\r] but ")" found."

Test SQL content:

ddl_test.sql ddl_test_extended.sql

create table test.table1
(
    id uuid not null
        primary key
);

create table test.table2
(
    id     uuid not null
        primary key,
    ref_id uuid
        references table1
);

Expected behavior The import of the SQL file should work.

Screenshots Image

Desktop (please complete the following information):

  • OS: Windows
  • Browser Chrome

Additional context The second test file is slightly extended (one more column) and results in a different Syntax Error:

SyntaxError [Ln 12, Col 26]: Expected "(", "--", ".", "/*", [ \t\n\r], or [A-Za-z0-9_\-$一-龥À-ſ] but "," found.

emschu avatar Oct 29 '25 17:10 emschu

youre not specifying which column to reference

CREATE TABLE test.table1 (
    id UUID NOT NULL PRIMARY KEY
);

CREATE TABLE test.table2 (
    id UUID NOT NULL PRIMARY KEY,
    ref_id UUID REFERENCES test.table1(id)
);

1ilit avatar Oct 29 '25 18:10 1ilit

@1ilit Thank you very much. Well, you are right, however the given syntax without explicitly specifying a column is valid for Postgres as long as table1 has a primary key, which is the case.

Jetbrains DataGrip/JetBrains DDL generators for PostgreSQL generate SQL DDL using this shortcut notation. It would be great if drawdb could support this kind of notation as there might be a lot of users working with JetBrains tooling.

emschu avatar Oct 29 '25 18:10 emschu