Skip to content

PostgreSQL SQL export: missing semicolon after CREATE TABLE and empty table name in CREATE INDEX statement #2591

Open

Description

@bernd670

Description

When exporting a PostgreSQL table structure (via "Export database as SQL" or table context menu) for a table that has both a UNIQUE constraint and a separate explicit index on the same column, the generated SQL is invalid / incomplete in several ways:

  1. There is no semicolon after the closing parenthesis of the CREATE TABLE statement, before the following CREATE INDEX statement begins. This causes the SQL parser to interpret both statements as one, resulting in a syntax error.
  2. In the generated CREATE INDEX statement, the table name in the ON clause is empty (ON "") instead of containing the actual table name.
  3. The schema qualification (e.g. public.) is missing from the table reference.
  4. The index method and operator class (USING btree (name varchar_pattern_ops)) are missing entirely from the exported statement.

This happens for every export, whether a single table or multiple tables are exported.

HeidiSQL version and OS

12.21.0.7344 Windows 11 25h2

Database server version

PostgreSQL 15.17 and PostgreSQL 16.15

Reproduction recipe

  1. Create a PostgreSQL table with a UNIQUE constraint, e.g.:
CREATE TABLE "table1" (
	"id" BIGINT NOT NULL,
	"name" VARCHAR(100) NOT NULL,
	"created_at" TIMESTAMPTZ NOT NULL,
	PRIMARY KEY ("id"),
	UNIQUE ("name")
);
CREATE INDEX table1_name_4c683569_like ON "table1" USING btree (name varchar_pattern_ops);
  1. Export the table structure as SQL (single table or multiple tables, same result).
  2. Observe the generated output:
CREATE TABLE IF NOT EXISTS "table1" (
	"id" BIGINT NOT NULL,
	"name" VARCHAR(100) NOT NULL,
	"created_at" TIMESTAMPTZ NOT NULL,
	PRIMARY KEY ("id"),
	UNIQUE ("name")
)
CREATE INDEX "table1_name_4c683569_like" ON "" ("name");;

Expected behavior

CREATE TABLE IF NOT EXISTS "table1" (
	"id" BIGINT NOT NULL,
	"name" VARCHAR(100) NOT NULL,
	"created_at" TIMESTAMPTZ NOT NULL,
	PRIMARY KEY ("id"),
	UNIQUE ("name")
);
CREATE INDEX table1_name_4c683569_like ON "table1" USING btree (name varchar_pattern_ops);

Additional notes

This index naming/operator-class pattern (_like suffix, varchar_pattern_ops) is commonly auto-generated by Django ORM migrations for indexed/unique CharField/TextField columns, to support pattern-matching (LIKE) queries efficiently regardless of database locale. This may be relevant context for reproducing the underlying table setup, though the export bug itself is independent of how the table was created.

Using CREATE INDEX IF NOT EXISTS instead of CREATE INDEX would additionally make the generated script idempotent/re-runnable, which may be worth considering as an enhancement alongside the fix.

Error/Backtrace

Activity

  1. added
    bugDefective behaviour in HeidiSQL
    on Sep 5, 2026
  2. ansgarbecker commented on Sep 10, 2026

    @ansgarbecker
    Collaborator

    The SQL export is quite MySQL/MariaDB only - other systems are only supported in a few basic things like a pure data-only export. There are a number of issue reports here referring to enhancing the SQL export for PG.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugDefective behaviour in HeidiSQLnettype-postgresqlPostgreSQL specific issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions