COPY manual is ambiguous about column list

From: PG Doc comments form <noreply(at)postgresql(dot)org>
To: pgsql-docs(at)lists(dot)postgresql(dot)org
Cc: pavlo(dot)golub(at)gmail(dot)com
Subject: COPY manual is ambiguous about column list
Date: 2019-11-27 17:54:53
Message-ID: 157487729344.7213.14245726713444755296@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

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(at)PG480 MINGW64 ~
$ echo "col1,col2,col3" > test.csv

pasha(at)PG480 MINGW64 ~
$ cat test.csv
col1,col2,col3

pasha(at)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

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Laurenz Albe 2019-11-28 09:47:10 Re: COPY manual is ambiguous about column list
Previous Message Jeff Janes 2019-11-27 16:33:03 document effect of USAGE on foreign server to dblink