You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PostgreSQL SQL export: missing semicolon after CREATE TABLE and empty table name in CREATE INDEX statement #2591
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:
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.
In the generated CREATE INDEX statement, the table name in the ON clause is empty (ON "") instead of containing the actual table name.
The schema qualification (e.g. public.) is missing from the table reference.
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
Create a PostgreSQL table with a UNIQUE constraint, e.g.:
CREATETABLEIF NOT EXISTS "table1" (
"id"BIGINTNOT NULL,
"name"VARCHAR(100) NOT NULL,
"created_at"TIMESTAMPTZNOT NULL,
PRIMARY KEY ("id"),
UNIQUE ("name")
);
CREATEINDEXtable1_name_4c683569_likeON"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.
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.
Activity
ansgarbecker commentedon Sep 10, 2026
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.