[feature]COPY FROM enable FORCE_NULL/FORCE_NOT_NULL on all columns - Mailing list pgsql-hackers

From Zhang Mingli
Subject [feature]COPY FROM enable FORCE_NULL/FORCE_NOT_NULL on all columns
Date
Msg-id 8d26836e-6de2-4d73-b079-9f883d922978@Spark
Whole thread Raw
Responses Re: [feature]COPY FROM enable FORCE_NULL/FORCE_NOT_NULL on all columns
Re: [feature]COPY FROM enable FORCE_NULL/FORCE_NOT_NULL on all columns
List pgsql-hackers
Hi, 

The previous discussion is:

https://www.postgresql.org/message-id/CACJufxEnVqzOFtqhexF2%2BAwOKFrV8zHOY3y%3Dp%2BgPK6eB14pn_w%40mail.gmail.com


We  have FORCE_NULL/FORCE_NOT_NULL options when COPY FROM,  but users must set the columns one by one.

 CREATE TABLE forcetest (
 a INT NOT NULL,
 b TEXT NOT NULL,
 c TEXT,
 d TEXT,
 e TEXT
 );
 \pset null NULL

 BEGIN;
 COPY forcetest (a, b, c, d) FROM STDIN WITH (FORMAT csv, FORCE_NOT_NULL(c,d), FORCE_NULL(c,d));
 1,'a',,""
 \.
 COMMIT;

 SELECT c, d FROM forcetest WHERE a = 1;
 c | d
 ---+------
 | NULL
 (1 row)


We don’t have  FORCE_NULL * or FORCE_NOT_NULL * for all columns of a table like FORCE_QUOTE *.

They should be helpful if a table have many columns.

This  patch enables FORCE_NULL/FORCE_NOT_NULL options to select all columns of a table  just like FORCE_QUOTE * (quote all columns).


 BEGIN
 COPY forcetest (a, b, c, d) FROM STDIN WITH (FORMAT csv, FORCE_NOT_NULL *, FORCE_NULL *);
 2,'b',,""
 \.
 COMMIT;

 SELECT c, d FROM forcetest WHERE a = 2;
 c | d
 ---+------
 | NULL
 (1 row)

Any thoughts?

Regards,
Zhang Mingli
Attachment

pgsql-hackers by date:

Previous
From: David Geier
Date:
Subject: Re: Reducing planning time on tables with many indexes
Next
From: Tom Lane
Date:
Subject: Re: Typo in pg_db_role_setting.h