pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

dump omits non-default column collations

Open milalintabach opened this issue 2 months ago • 0 comments

Summary

pgschema dump omits a column's explicitly configured non-default collation. This changes the semantics of a schema recreated from the dump, including the collation inherited by indexes on that column.

Reproduction

CREATE SCHEMA collation_repro;

CREATE TABLE collation_repro.recipient_search (
    id bigint PRIMARY KEY,
    search_text text COLLATE "C" NOT NULL
);

CREATE INDEX recipient_search_prefix_idx
    ON collation_repro.recipient_search (search_text text_pattern_ops);
pgschema dump --schema collation_repro --no-comments

Actual output

CREATE TABLE IF NOT EXISTS recipient_search (
    id bigint,
    search_text text NOT NULL,
    CONSTRAINT recipient_search_pkey PRIMARY KEY (id)
);

CREATE INDEX IF NOT EXISTS recipient_search_prefix_idx
    ON recipient_search (search_text text_pattern_ops);

Expected output

The table declaration should preserve the explicit collation:

CREATE TABLE IF NOT EXISTS recipient_search (
    id bigint,
    search_text text COLLATE "C" NOT NULL,
    CONSTRAINT recipient_search_pkey PRIMARY KEY (id)
);

The index can continue to inherit the column collation once the column declaration is preserved.

Impact

Applying the generated dump on a database whose default collation is not C recreates the column and its index with a different collation. That can change ordering and prefix-search behavior, so the generated schema is not a faithful round trip.

Environment

  • pgschema 1.13.0 (current latest release)
  • PostgreSQL 18.4
  • macOS arm64 pgschema release binary

I also searched the existing open and closed issues for a collation report and did not find one covering this behavior.

milalintabach avatar Sep 09 '26 13:09 milalintabach