From: | Zhang Mingli <zmlpostgres(at)gmail(dot)com> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | [feature]COPY FROM enable FORCE_NULL/FORCE_NOT_NULL on all columns |
Date: | 2022-08-01 13:56:14 |
Message-ID: | 8d26836e-6de2-4d73-b079-9f883d922978@Spark |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
The previous discussion is:
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 | Content-Type | Size |
---|---|---|
v0001-COPY-FROM-enable-FORCE_NULL-FORCE_NOT_NULL-on-all-columns.patch | application/octet-stream | 10.5 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2022-08-01 14:16:08 | Re: Typo in pg_db_role_setting.h |
Previous Message | David Geier | 2022-08-01 13:33:55 | Re: Reducing planning time on tables with many indexes |