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?