-
Notifications
You must be signed in to change notification settings - Fork 49
fix: preserve length modifier in varchar(n)[] array columns (#420) #438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vytautas-karpavicius
wants to merge
1
commit into
pgplex:main
Choose a base branch
from
vytautas-karpavicius:fix-issue-420
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
testdata/dump/issue_420_varchar_array_length_modifier/manifest.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "name": "issue_420_varchar_array_length_modifier", | ||
| "description": "pgschema dump silently drops the length modifier from varchar(n)[] array columns, emitting varchar[] instead of varchar(128)[]", | ||
| "source": "https://github.com/pgplex/pgschema/issues/420", | ||
| "notes": [ | ||
| "The SQL query for array types used et.typname || '[]' which discards the atttypmod", | ||
| "The fix uses format_type(a.atttypid, a.atttypmod) to extract the modifier (e.g., (128))", | ||
| "Also covers character(n)[] which had the same bug (bpchar typname)" | ||
| ] | ||
| } |
33 changes: 33 additions & 0 deletions
33
testdata/dump/issue_420_varchar_array_length_modifier/pgdump.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| -- | ||
| -- PostgreSQL database dump | ||
| -- | ||
|
|
||
| SET statement_timeout = 0; | ||
| SET lock_timeout = 0; | ||
| SET client_encoding = 'UTF8'; | ||
| SET standard_conforming_strings = on; | ||
| SET check_function_bodies = false; | ||
| SET client_min_messages = warning; | ||
| SET row_security = off; | ||
|
|
||
| -- | ||
| -- Name: items; Type: TABLE; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| CREATE TABLE public.items ( | ||
| id integer NOT NULL, | ||
| name character varying(64), | ||
| tags character varying(128)[], | ||
| codes character(10)[] | ||
| ); | ||
|
|
||
| -- | ||
| -- Name: items items_pkey; Type: CONSTRAINT; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| ALTER TABLE ONLY public.items | ||
| ADD CONSTRAINT items_pkey PRIMARY KEY (id); | ||
|
|
||
| -- | ||
| -- PostgreSQL database dump complete | ||
| -- |
20 changes: 20 additions & 0 deletions
20
testdata/dump/issue_420_varchar_array_length_modifier/pgschema.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| -- | ||
| -- pgschema database dump | ||
| -- | ||
|
|
||
| -- Dumped from database version PostgreSQL 18.0 | ||
| -- Dumped by pgschema version 1.9.0 | ||
|
|
||
|
|
||
| -- | ||
| -- Name: items; Type: TABLE; Schema: -; Owner: - | ||
| -- | ||
|
|
||
| CREATE TABLE IF NOT EXISTS items ( | ||
| id integer, | ||
| name varchar(64), | ||
| tags varchar(128)[], | ||
| codes character(10)[], | ||
| CONSTRAINT items_pkey PRIMARY KEY (id) | ||
| ); | ||
|
|
13 changes: 13 additions & 0 deletions
13
testdata/dump/issue_420_varchar_array_length_modifier/raw.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| -- | ||
| -- Test case for GitHub issue #420: varchar(n)[] length modifier silently dropped in dump | ||
| -- | ||
| -- The length modifier is lost when dumping array columns of character types | ||
| -- with a length constraint: varchar(128)[] is emitted as varchar[]. | ||
| -- | ||
|
|
||
| CREATE TABLE items ( | ||
| id integer PRIMARY KEY, | ||
| name varchar(64), | ||
| tags varchar(128)[], | ||
| codes character(10)[] | ||
| ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 becomesinterval(3)[]and dropsDAY TO SECOND. That changes the column type semantics in the dump.