-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: pg_dump text array format not compatible with COPY #56593
Comments
Hello, I am Blathers. I am here to help you get the issue triaged. It looks like you have not filled out the issue in the format of any of our templates. To best assist you, we advise you to use one of these templates. I have CC'd a few people who may be able to assist you:
If we have not gotten back to your issue within a few business days, you can try the following:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
Thanks for filing this, @nbir. |
Noting stuff here since I can't fully test everything yet: Seems like the issue is in
If we were to use the default case here, it actually works fine. From what I can see, this was added in #44464 in order to make cockroach dump/import round-trip correctly. But I don't think we really need to use It seems to work if I change |
This also is covered in #29043 |
58244: importccl: Fixed COPY FROM STDIN compatibility for IMPORT pgdump array data r=miretskiy a=mokaixu Previously, when users imported pgdumps that contained populated tables with array (ex. text[]) column types, a parsing error would occur when data was populated with COPY FROM STDIN. We currently support INSERTing array data using the ARRAY function or casting it from a string when the data is enclosed in single quotes (ex. '{3,4}'). Now, we can IMPORT pgdump a file that COPY FROM STDIN array data (Note that the PGdumped array will be formatted with curly braces without quotes ({3,4}). Release note: bug fix Parsing errors are no longer thrown when importing a pgdump file with array data. Fixes: #29043 , #56593 Co-authored-by: Monica Xu <[email protected]>
closed by #58244 |
The Problem
When importing a PostgreSQL dump file using the COPY statement (instead of INSERT), text array columns, as represented by PostgreSQL, are not compatible with CockroachDB.
Using
pg_dump
, a column of datatypetext[]
, would be exported as{foobar,baz}
.CockroachDB IMPORT expects it to be
'{"foobar","baz"}'
(quoted strings). However, this format is incompatible when restoring into PostgreSQL usingpsql
.The only formats compatible with restoring into PostgreSQL are
{foobar,baz}
and{"foobar","baz"}
.Expected Behavior
To maintain compatibility of input formats between PostgreSQL and CockroachDB, we would expect CockroachDB IMPORT to work with PostgreSQL dump as is. CockroachDB IMPORT should accept
text[]
fields in the{foobar,baz}
format when using the COPY statement.Known Workaround
We can get around this issue by using
pg_dump
with the--inserts
flag. This generates a separate INSERT command for each row instead of a single COPY statement. This approach has two drawbacks:Another workaround is to hand-manipulate (as shown below) or programmatically manipulate the PostgreSQL dump file to modify text array columns to match the format expected by CockroachDB.
To Reproduce
Files: files.zip
Key Steps
Requires CockroachDB running locally (using this guide).
test_text_array
database.pg_dump.sql
file, run the following command in the CockroachDB SQL client. This step will fail because of the incompatible format.Entire Process
Requires PostgreSQL and CockroachDB running locally (using this guide).
Creating a dump from PostgreSQL
text[]
) and insert some data by running the attachedpg_init.sql
file.pg_dump
by running the following command.test_text_array
database.Hand-manipulate dump file to be compatible with CockroachDB
Manually add quotes to text array fields. e.g. change
{foobar,baz}
in the PostgreSQL dump file to'{"foobar","baz"}'
.pg_dump_modified_for_crdb.sql
file. This import should work without any errors.Restore hand-manipulated dump file into PostgreSQL
Delete the existing
test_text_array
table in PostgreSQL and import the hand-manipulated dump file that is compatible with CockroachDB, into PostgreSQL.pg_dump_modified_for_crdb.sql
file, run the following command. This fails because the quoted string format for text arrays that is compatible with CockroachDB is not compatible with PostgreSQL.Environment:
The text was updated successfully, but these errors were encountered: