public inbox for [email protected]
help / color / mirror / Atom feedFrom: PG Doc comments form <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: COPY manual is ambiguous about column list
Date: Wed, 27 Nov 2019 17:54:53 +0000
Message-ID: <[email protected]> (raw)
The following documentation comment has been logged on the website:
Page: https://www.postgresql.org/docs/12/sql-copy.html
Description:
"If a list of columns is specified, COPY will only copy the data in the
specified columns to or from the file. If there are any columns in the table
that are not in the column list, COPY FROM will insert the default values
for those columns."
I clearly see "to or from" file here. But if one tries to COPY FROM filename
with more columns than list specified, the process fails:
```
pasha@PG480 MINGW64 ~
$ echo "col1,col2,col3" > test.csv
pasha@PG480 MINGW64 ~
$ cat test.csv
col1,col2,col3
pasha@PG480 MINGW64 ~
$ psql -d migrator
migrator=# CREATE TABLE copy_test(col1 text, col2 text);
CREATE TABLE
migrator=# COPY copy_test(col1, col2) FROM 'test.csv' (FORMAT csv);
ERROR: extra data after last expected column
CONTEXT: COPY copy_test, line 1: "col1,col2,col3"
```
I believe this statement should be rewritten, e.g.
"If a list of columns is specified, COPY will only copy the data in the
specified columns to the file. The input file should contain the same number
of columns as the list specified, otherwise COPY FROM will fail. One may use
`awk` to preprocess the input file and remove extra columns. If there are
any columns in the table that are not in the column list, COPY FROM will
insert the default values for those columns."
https://www.postgresql.org/docs/12/sql-copy.html
view thread (16+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: COPY manual is ambiguous about column list
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox