1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-22 14:32:25 +03:00

Add a DEFAULT option to COPY FROM

This allows for a string which if an input field matches causes the
column's default value to be inserted. The advantage of this is that
the default can be inserted in some rows and not others, for which
non-default data is available.

The file_fdw extension is also modified to take allow use of this
option.

Israel Barth Rubio

Discussion: https://postgr.es/m/CAO_rXXAcqesk6DsvioOZ5zmeEmpUN5ktZf-9=9yu+DTr0Xr8Uw@mail.gmail.com
This commit is contained in:
Andrew Dunstan
2023-03-13 10:01:56 -04:00
parent 7b14e20b12
commit 9f8377f7a2
15 changed files with 447 additions and 24 deletions

View File

@@ -47,6 +47,8 @@ typedef struct CopyFormatOptions
char *null_print; /* NULL marker string (server encoding!) */
int null_print_len; /* length of same */
char *null_print_client; /* same converted to file encoding */
char *default_print; /* DEFAULT marker string */
int default_print_len; /* length of same */
char *delim; /* column delimiter (must be 1 byte) */
char *quote; /* CSV quote char (must be 1 byte) */
char *escape; /* CSV escape char (must be 1 byte) */

View File

@@ -44,8 +44,7 @@ typedef enum EolType
*/
typedef enum CopyInsertMethod
{
CIM_SINGLE, /* use table_tuple_insert or
* ExecForeignInsert */
CIM_SINGLE, /* use table_tuple_insert or ExecForeignInsert */
CIM_MULTI, /* always use table_multi_insert or
* ExecForeignBatchInsert */
CIM_MULTI_CONDITIONAL /* use table_multi_insert or
@@ -91,11 +90,16 @@ typedef struct CopyFromStateData
*/
MemoryContext copycontext; /* per-copy execution context */
AttrNumber num_defaults;
AttrNumber num_defaults; /* count of att that are missing and have
* default value */
FmgrInfo *in_functions; /* array of input functions for each attrs */
Oid *typioparams; /* array of element types for in_functions */
int *defmap; /* array of default att numbers */
ExprState **defexprs; /* array of default att expressions */
int *defmap; /* array of default att numbers related to
* missing att */
ExprState **defexprs; /* array of default att expressions for all
* att */
bool *defaults; /* if DEFAULT marker was found for
* corresponding att */
bool volatile_defexprs; /* is any of defexprs volatile? */
List *range_table; /* single element list of RangeTblEntry */
List *rteperminfos; /* single element list of RTEPermissionInfo */