Skip to content

[BUG] PostgreSQL Import fails with Syntax Error on valid pg_dump files #852

@Gautam-Bharadwaj

Description

@Gautam-Bharadwaj

#PR - #852 (Bug fixing)


Describe the bug
When importing a SQL script generated by pg_dump (PostgreSQL), the application fails to generate the diagram and displays a "Syntax Error" message. This happens even for valid SQL files because the parser (node-sql-parser) crashes when it encounters standard PostgreSQL dump artefacts like comments (--), configuration commands (SET statement_timeout...), or extensions (CREATE EXTENSION).

To Reproduce
Steps to reproduce the behaviour:

  1. Generate a dump file from a PostgreSQL database using pg_dump (or use a SQL file containing SET commands or comments).
  2. Open DrawDB and click File > Import SQL.
  3. Paste the SQL content or upload the file.
  4. See error: "Syntax Error due to token..." (or generally failing to load).

Expected behaviour
The application should successfully parse the DDL statements (CREATE TABLE, ALTER TABLE) to generate the diagram, while ignoring non-structural metadata like comments or session variable configurations.

Desktop (please complete the following information):

  • OS: macOS / Windows / Linux (Platform Independent)
  • Browser Chrome / Firefox / Safari

Additional context
The issue stems from the strictness of the node-sql-parser library. It does not support specific pg_dump meta-commands. A fix involves sanitising the SQL input to strip these artefacts before parsing. I have prepared a PR for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions