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