Skip to content

fix: preserve length modifier in varchar(n)[] array columns (#420)#438

Open
vytautas-karpavicius wants to merge 1 commit into
pgplex:mainfrom
vytautas-karpavicius:fix-issue-420
Open

fix: preserve length modifier in varchar(n)[] array columns (#420)#438
vytautas-karpavicius wants to merge 1 commit into
pgplex:mainfrom
vytautas-karpavicius:fix-issue-420

Conversation

@vytautas-karpavicius
Copy link
Copy Markdown

This PR fixes issue #420

  • pgschema dump silently dropped the length modifier from array columns whose element type carries a typmod (e.g. varchar(128)[] was emitted as varchar[])
  • The inspector SQL used et.typname || '[]' for array types, which discards atttypmod. Non-array types already used format_type(a.atttypid, a.atttypmod) to extract the modifier — array types now do the same
  • normalizePostgreSQLType is updated to handle types-with-modifiers (e.g. bpchar(10)[] -> character(10)[]) by decomposing the type name once and doing a single map lookup instead of two

Test plan

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 18, 2026

Greptile Summary

This PR preserves length modifiers for character array columns in schema dumps. The main changes are:

  • Updates column inspector SQL to append array element typmods.
  • Extends PostgreSQL type normalization for mapped names with modifiers.
  • Adds an integration fixture for varchar(n)[] and character(n)[] dumps.

Confidence Score: 3/5

This should be fixed before merging.

  • Character array typmods are handled for the covered cases.

  • Interval array columns with field ranges can be dumped with the wrong type.

  • The same SQL expression appears in both column query variants and the generated query file.

  • ir/queries/queries.sql

  • ir/queries/queries.sql.go

Important Files Changed

Filename Overview
ir/queries/queries.sql Adds typmod reconstruction for array column types, but the substring approach can lose interval field ranges.
ir/normalize.go Normalizes mapped PostgreSQL type names while preserving parenthesized modifiers and suffixes.

Reviews (1): Last reviewed commit: "fix: preserve length modifier in varchar..." | Re-trigger Greptile

Comment thread ir/queries/queries.sql
WHEN en.nspname = 'pg_catalog' THEN et.typname
WHEN en.nspname = c.table_schema THEN et.typname
ELSE en.nspname || '.' || et.typname
END || COALESCE(substring(format_type(a.atttypid, a.atttypmod) FROM '\([^)]*\)'), '') || '[]'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Preserve interval fields When an array column uses an interval field range, such as INTERVAL DAY TO SECOND(3)[], format_type(a.atttypid, a.atttypmod) includes both the fields and the precision. This substring only keeps the parenthesized precision, so the dumped type becomes interval(3)[] and drops DAY TO SECOND. That changes the column type semantics in the dump.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants