From 072132f04e55c1c3b0f1a582318da78de7334379 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 30 Mar 2022 08:56:58 +0200 Subject: Add header matching mode to COPY FROM COPY FROM supports the HEADER option to silently discard the header line from a CSV or text file. It is possible to load by mistake a file that matches the expected format, for example, if two text columns have been swapped, resulting in garbage in the database. This adds a new option value HEADER MATCH that checks the column names in the header line against the actual column names and errors out if they do not match. Author: Rémi Lapeyre Reviewed-by: Daniel Verite Reviewed-by: Peter Eisentraut Discussion: https://www.postgresql.org/message-id/flat/CAF1-J-0PtCWMeLtswwGV2M70U26n4g33gpe1rcKQqe6wVQDrFA@mail.gmail.com --- doc/src/sgml/ref/copy.sgml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/ref/copy.sgml b/doc/src/sgml/ref/copy.sgml index 1b7d0019636..e7a6676efd0 100644 --- a/doc/src/sgml/ref/copy.sgml +++ b/doc/src/sgml/ref/copy.sgml @@ -36,7 +36,7 @@ COPY { table_name [ ( boolean ] DELIMITER 'delimiter_character' NULL 'null_string' - HEADER [ boolean ] + HEADER [ boolean | match ] QUOTE 'quote_character' ESCAPE 'escape_character' FORCE_QUOTE { ( column_name [, ...] ) | * } @@ -276,7 +276,11 @@ COPY { table_name [ ( Specifies that the file contains a header line with the names of each column in the file. On output, the first line contains the column - names from the table, and on input, the first line is ignored. + names from the table. On input, the first line is discarded when this + option is set to true (or equivalent Boolean value). + If this option is set to match, the number and names + of the columns in the header line must match the actual column names of + the table, otherwise an error is raised. This option is not allowed when using binary format. -- cgit v1.2.3