Skip to content

Postgres: postgres.indexes entry without a name fails with "zero-length delimited identifier" #31

Description

@ihistand

Found during the 1.4.0 acceptance pass (#17), real-user flow: published @sqlanvil/cli@1.4.0 against a local Postgres, no repo checkout.

Repro

config {
  type: "table",
  postgres: { indexes: [ { columns: ["id"], unique: true } ] }
}
SELECT 1 AS id

sqlanvil run

Dataset creation failed: sqlanvil.iso_idx [table]
postgres error: Error executing postgres query: zero-length delimited identifier at or near """"

Cause

An index config entry that omits name generates CREATE [UNIQUE] INDEX "" ON ... — an empty ("") index identifier — which Postgres rejects. No index name is auto-generated.

Confirmation

Adding an explicit name works and the index is created correctly:

postgres: { indexes: [ { name: "iso_idx_named_id_uq", columns: ["id"], unique: true } ] }

Table created, \di shows iso_idx_named_id_uq.

fillfactor alone and description/columns (COMMENTs) alone are unaffected — the bug is specific to index entries without a name.

Impact

Blocker-level for a common case: a table with any unnamed postgres.indexes entry fails to create. The MVP checklist's own example (mvp_user_test_checklist.md §4) omits the name, so a doc-following user hits a hard failure.

Fix direction

Auto-generate an index name when name is omitted (e.g. <table>_<col1>_<col2>_idx, matching Postgres's own default naming, deduped/truncated to 63 chars), in the Postgres execution-SQL index generator. Add a unit test for the no-name case and an integration test in postgres.spec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions