mirror of
https://github.com/postgres/postgres.git
synced 2025-10-19 15:49:24 +03:00
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 <remi.lapeyre@lenstra.fr> Reviewed-by: Daniel Verite <daniel@manitou-mail.org> Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/CAF1-J-0PtCWMeLtswwGV2M70U26n4g33gpe1rcKQqe6wVQDrFA@mail.gmail.com
This commit is contained in:
@@ -19,6 +19,17 @@
|
||||
#include "parser/parse_node.h"
|
||||
#include "tcop/dest.h"
|
||||
|
||||
/*
|
||||
* Represents whether a header line should be present, and whether it must
|
||||
* match the actual names (which implies "true").
|
||||
*/
|
||||
typedef enum CopyHeaderChoice
|
||||
{
|
||||
COPY_HEADER_FALSE = 0,
|
||||
COPY_HEADER_TRUE,
|
||||
COPY_HEADER_MATCH,
|
||||
} CopyHeaderChoice;
|
||||
|
||||
/*
|
||||
* A struct to hold COPY options, in a parsed form. All of these are related
|
||||
* to formatting, except for 'freeze', which doesn't really belong here, but
|
||||
@@ -32,7 +43,7 @@ typedef struct CopyFormatOptions
|
||||
bool binary; /* binary format? */
|
||||
bool freeze; /* freeze rows on loading? */
|
||||
bool csv_mode; /* Comma Separated Value format? */
|
||||
bool header_line; /* header line? */
|
||||
CopyHeaderChoice header_line; /* header line? */
|
||||
char *null_print; /* NULL marker string (server encoding!) */
|
||||
int null_print_len; /* length of same */
|
||||
char *null_print_client; /* same converted to file encoding */
|
||||
|
Reference in New Issue
Block a user