2009-06-14 02:00:24 +02:00
|
|
|
CREATE TEMP TABLE x (
|
2002-07-18 06:45:51 +02:00
|
|
|
a serial,
|
|
|
|
b int,
|
|
|
|
c text not null default 'stuff',
|
2003-10-10 05:46:51 +02:00
|
|
|
d text,
|
2002-07-18 06:45:51 +02:00
|
|
|
e text
|
Remove WITH OIDS support, change oid catalog column visibility.
Previously tables declared WITH OIDS, including a significant fraction
of the catalog tables, stored the oid column not as a normal column,
but as part of the tuple header.
This special column was not shown by default, which was somewhat odd,
as it's often (consider e.g. pg_class.oid) one of the more important
parts of a row. Neither pg_dump nor COPY included the contents of the
oid column by default.
The fact that the oid column was not an ordinary column necessitated a
significant amount of special case code to support oid columns. That
already was painful for the existing, but upcoming work aiming to make
table storage pluggable, would have required expanding and duplicating
that "specialness" significantly.
WITH OIDS has been deprecated since 2005 (commit ff02d0a05280e0).
Remove it.
Removing includes:
- CREATE TABLE and ALTER TABLE syntax for declaring the table to be
WITH OIDS has been removed (WITH (oids[ = true]) will error out)
- pg_dump does not support dumping tables declared WITH OIDS and will
issue a warning when dumping one (and ignore the oid column).
- restoring an pg_dump archive with pg_restore will warn when
restoring a table with oid contents (and ignore the oid column)
- COPY will refuse to load binary dump that includes oids.
- pg_upgrade will error out when encountering tables declared WITH
OIDS, they have to be altered to remove the oid column first.
- Functionality to access the oid of the last inserted row (like
plpgsql's RESULT_OID, spi's SPI_lastoid, ...) has been removed.
The syntax for declaring a table WITHOUT OIDS (or WITH (oids = false)
for CREATE TABLE) is still supported. While that requires a bit of
support code, it seems unnecessary to break applications / dumps that
do not use oids, and are explicit about not using them.
The biggest user of WITH OID columns was postgres' catalog. This
commit changes all 'magic' oid columns to be columns that are normally
declared and stored. To reduce unnecessary query breakage all the
newly added columns are still named 'oid', even if a table's column
naming scheme would indicate 'reloid' or such. This obviously
requires adapting a lot code, mostly replacing oid access via
HeapTupleGetOid() with access to the underlying Form_pg_*->oid column.
The bootstrap process now assigns oids for all oid columns in
genbki.pl that do not have an explicit value (starting at the largest
oid previously used), only oids assigned later by oids will be above
FirstBootstrapObjectId. As the oid column now is a normal column the
special bootstrap syntax for oids has been removed.
Oids are not automatically assigned during insertion anymore, all
backend code explicitly assigns oids with GetNewOidWithIndex(). For
the rare case that insertions into the catalog via SQL are called for
the new pg_nextoid() function can be used (which only works on catalog
tables).
The fact that oid columns on system tables are now normal columns
means that they will be included in the set of columns expanded
by * (i.e. SELECT * FROM pg_class will now include the table's oid,
previously it did not). It'd not technically be hard to hide oid
column by default, but that'd mean confusing behavior would either
have to be carried forward forever, or it'd cause breakage down the
line.
While it's not unlikely that further adjustments are needed, the
scope/invasiveness of the patch makes it worthwhile to get merge this
now. It's painful to maintain externally, too complicated to commit
after the code code freeze, and a dependency of a number of other
patches.
Catversion bump, for obvious reasons.
Author: Andres Freund, with contributions by John Naylor
Discussion: https://postgr.es/m/20180930034810.ywp2c7awz7opzcfr@alap3.anarazel.de
2018-11-21 00:36:57 +01:00
|
|
|
) ;
|
2002-07-18 06:45:51 +02:00
|
|
|
|
2002-08-22 02:01:51 +02:00
|
|
|
CREATE FUNCTION fn_x_before () RETURNS TRIGGER AS '
|
2002-07-18 06:45:51 +02:00
|
|
|
BEGIN
|
|
|
|
NEW.e := ''before trigger fired''::text;
|
|
|
|
return NEW;
|
|
|
|
END;
|
2006-02-27 17:09:50 +01:00
|
|
|
' LANGUAGE plpgsql;
|
2002-07-18 06:45:51 +02:00
|
|
|
|
2002-08-22 02:01:51 +02:00
|
|
|
CREATE FUNCTION fn_x_after () RETURNS TRIGGER AS '
|
2002-07-18 06:45:51 +02:00
|
|
|
BEGIN
|
|
|
|
UPDATE x set e=''after trigger fired'' where c=''stuff'';
|
|
|
|
return NULL;
|
|
|
|
END;
|
2006-02-27 17:09:50 +01:00
|
|
|
' LANGUAGE plpgsql;
|
2002-07-18 06:45:51 +02:00
|
|
|
|
|
|
|
CREATE TRIGGER trg_x_after AFTER INSERT ON x
|
|
|
|
FOR EACH ROW EXECUTE PROCEDURE fn_x_after();
|
|
|
|
|
|
|
|
CREATE TRIGGER trg_x_before BEFORE INSERT ON x
|
|
|
|
FOR EACH ROW EXECUTE PROCEDURE fn_x_before();
|
|
|
|
|
2002-07-30 18:55:06 +02:00
|
|
|
COPY x (a, b, c, d, e) from stdin;
|
2003-10-10 05:46:51 +02:00
|
|
|
9999 \N \\N \NN \N
|
2002-07-18 06:45:51 +02:00
|
|
|
10000 21 31 41 51
|
|
|
|
\.
|
|
|
|
|
2002-07-30 18:55:06 +02:00
|
|
|
COPY x (b, d) from stdin;
|
2002-07-18 06:45:51 +02:00
|
|
|
1 test_1
|
|
|
|
\.
|
|
|
|
|
2002-07-30 18:55:06 +02:00
|
|
|
COPY x (b, d) from stdin;
|
2002-07-18 06:45:51 +02:00
|
|
|
2 test_2
|
|
|
|
3 test_3
|
|
|
|
4 test_4
|
|
|
|
5 test_5
|
|
|
|
\.
|
|
|
|
|
2002-07-30 18:55:06 +02:00
|
|
|
COPY x (a, b, c, d, e) from stdin;
|
2002-07-18 06:45:51 +02:00
|
|
|
10001 22 32 42 52
|
|
|
|
10002 23 33 43 53
|
|
|
|
10003 24 34 44 54
|
|
|
|
10004 25 35 45 55
|
|
|
|
10005 26 36 46 56
|
|
|
|
\.
|
|
|
|
|
2002-07-30 18:55:06 +02:00
|
|
|
-- non-existent column in column list: should fail
|
|
|
|
COPY x (xyz) from stdin;
|
|
|
|
|
2020-10-05 02:43:17 +02:00
|
|
|
-- redundant options
|
|
|
|
COPY x from stdin (format CSV, FORMAT CSV);
|
|
|
|
COPY x from stdin (freeze off, freeze on);
|
|
|
|
COPY x from stdin (delimiter ',', delimiter ',');
|
|
|
|
COPY x from stdin (null ' ', null ' ');
|
|
|
|
COPY x from stdin (header off, header on);
|
|
|
|
COPY x from stdin (quote ':', quote ':');
|
|
|
|
COPY x from stdin (escape ':', escape ':');
|
|
|
|
COPY x from stdin (force_quote (a), force_quote *);
|
|
|
|
COPY x from stdin (force_not_null (a), force_not_null (b));
|
|
|
|
COPY x from stdin (force_null (a), force_null (b));
|
|
|
|
COPY x from stdin (convert_selectively (a), convert_selectively (b));
|
|
|
|
COPY x from stdin (encoding 'sql_ascii', encoding 'sql_ascii');
|
2024-01-19 14:08:40 +01:00
|
|
|
COPY x from stdin (on_error ignore, on_error ignore);
|
2020-10-05 02:43:17 +02:00
|
|
|
|
2022-11-02 01:57:54 +01:00
|
|
|
-- incorrect options
|
|
|
|
COPY x to stdin (format BINARY, delimiter ',');
|
|
|
|
COPY x to stdin (format BINARY, null 'x');
|
2024-01-19 14:08:40 +01:00
|
|
|
COPY x from stdin (format BINARY, on_error ignore);
|
|
|
|
COPY x from stdin (on_error unsupported);
|
2022-11-02 01:57:54 +01:00
|
|
|
COPY x to stdin (format TEXT, force_quote(a));
|
|
|
|
COPY x from stdin (format CSV, force_quote(a));
|
|
|
|
COPY x to stdout (format TEXT, force_not_null(a));
|
|
|
|
COPY x to stdin (format CSV, force_not_null(a));
|
|
|
|
COPY x to stdout (format TEXT, force_null(a));
|
|
|
|
COPY x to stdin (format CSV, force_null(a));
|
2024-01-19 14:08:40 +01:00
|
|
|
COPY x to stdin (format BINARY, on_error unsupported);
|
2022-11-02 01:57:54 +01:00
|
|
|
|
2002-07-30 18:55:06 +02:00
|
|
|
-- too many columns in column list: should fail
|
|
|
|
COPY x (a, b, c, d, e, d, c) from stdin;
|
|
|
|
|
|
|
|
-- missing data: should fail
|
|
|
|
COPY x from stdin;
|
|
|
|
|
|
|
|
\.
|
|
|
|
COPY x from stdin;
|
|
|
|
2000 230 23 23
|
|
|
|
\.
|
|
|
|
COPY x from stdin;
|
|
|
|
2001 231 \N \N
|
|
|
|
\.
|
|
|
|
|
|
|
|
-- extra data: should fail
|
|
|
|
COPY x from stdin;
|
|
|
|
2002 232 40 50 60 70 80
|
|
|
|
\.
|
|
|
|
|
2011-02-21 06:08:04 +01:00
|
|
|
-- various COPY options: delimiters, oids, NULL string, encoding
|
Remove WITH OIDS support, change oid catalog column visibility.
Previously tables declared WITH OIDS, including a significant fraction
of the catalog tables, stored the oid column not as a normal column,
but as part of the tuple header.
This special column was not shown by default, which was somewhat odd,
as it's often (consider e.g. pg_class.oid) one of the more important
parts of a row. Neither pg_dump nor COPY included the contents of the
oid column by default.
The fact that the oid column was not an ordinary column necessitated a
significant amount of special case code to support oid columns. That
already was painful for the existing, but upcoming work aiming to make
table storage pluggable, would have required expanding and duplicating
that "specialness" significantly.
WITH OIDS has been deprecated since 2005 (commit ff02d0a05280e0).
Remove it.
Removing includes:
- CREATE TABLE and ALTER TABLE syntax for declaring the table to be
WITH OIDS has been removed (WITH (oids[ = true]) will error out)
- pg_dump does not support dumping tables declared WITH OIDS and will
issue a warning when dumping one (and ignore the oid column).
- restoring an pg_dump archive with pg_restore will warn when
restoring a table with oid contents (and ignore the oid column)
- COPY will refuse to load binary dump that includes oids.
- pg_upgrade will error out when encountering tables declared WITH
OIDS, they have to be altered to remove the oid column first.
- Functionality to access the oid of the last inserted row (like
plpgsql's RESULT_OID, spi's SPI_lastoid, ...) has been removed.
The syntax for declaring a table WITHOUT OIDS (or WITH (oids = false)
for CREATE TABLE) is still supported. While that requires a bit of
support code, it seems unnecessary to break applications / dumps that
do not use oids, and are explicit about not using them.
The biggest user of WITH OID columns was postgres' catalog. This
commit changes all 'magic' oid columns to be columns that are normally
declared and stored. To reduce unnecessary query breakage all the
newly added columns are still named 'oid', even if a table's column
naming scheme would indicate 'reloid' or such. This obviously
requires adapting a lot code, mostly replacing oid access via
HeapTupleGetOid() with access to the underlying Form_pg_*->oid column.
The bootstrap process now assigns oids for all oid columns in
genbki.pl that do not have an explicit value (starting at the largest
oid previously used), only oids assigned later by oids will be above
FirstBootstrapObjectId. As the oid column now is a normal column the
special bootstrap syntax for oids has been removed.
Oids are not automatically assigned during insertion anymore, all
backend code explicitly assigns oids with GetNewOidWithIndex(). For
the rare case that insertions into the catalog via SQL are called for
the new pg_nextoid() function can be used (which only works on catalog
tables).
The fact that oid columns on system tables are now normal columns
means that they will be included in the set of columns expanded
by * (i.e. SELECT * FROM pg_class will now include the table's oid,
previously it did not). It'd not technically be hard to hide oid
column by default, but that'd mean confusing behavior would either
have to be carried forward forever, or it'd cause breakage down the
line.
While it's not unlikely that further adjustments are needed, the
scope/invasiveness of the patch makes it worthwhile to get merge this
now. It's painful to maintain externally, too complicated to commit
after the code code freeze, and a dependency of a number of other
patches.
Catversion bump, for obvious reasons.
Author: Andres Freund, with contributions by John Naylor
Discussion: https://postgr.es/m/20180930034810.ywp2c7awz7opzcfr@alap3.anarazel.de
2018-11-21 00:36:57 +01:00
|
|
|
COPY x (b, c, d, e) from stdin delimiter ',' null 'x';
|
|
|
|
x,45,80,90
|
|
|
|
x,\x,\\x,\\\x
|
|
|
|
x,\,,\\\,,\\
|
2003-10-10 05:46:51 +02:00
|
|
|
\.
|
|
|
|
|
|
|
|
COPY x from stdin WITH DELIMITER AS ';' NULL AS '';
|
|
|
|
3000;;c;;
|
|
|
|
\.
|
|
|
|
|
2011-02-21 06:08:04 +01:00
|
|
|
COPY x from stdin WITH DELIMITER AS ':' NULL AS E'\\X' ENCODING 'sql_ascii';
|
2003-10-10 05:46:51 +02:00
|
|
|
4000:\X:C:\X:\X
|
|
|
|
4001:1:empty::
|
|
|
|
4002:2:null:\X:\X
|
|
|
|
4003:3:Backslash:\\:\\
|
|
|
|
4004:4:BackslashX:\\X:\\X
|
|
|
|
4005:5:N:\N:\N
|
|
|
|
4006:6:BackslashN:\\N:\\N
|
|
|
|
4007:7:XX:\XX:\XX
|
|
|
|
4008:8:Delimiter:\::\:
|
2002-07-30 18:55:06 +02:00
|
|
|
\.
|
|
|
|
|
2019-01-19 23:48:16 +01:00
|
|
|
COPY x TO stdout WHERE a = 1;
|
|
|
|
COPY x from stdin WHERE a = 50004;
|
|
|
|
50003 24 34 44 54
|
|
|
|
50004 25 35 45 55
|
|
|
|
50005 26 36 46 56
|
|
|
|
\.
|
|
|
|
|
|
|
|
COPY x from stdin WHERE a > 60003;
|
|
|
|
60001 22 32 42 52
|
|
|
|
60002 23 33 43 53
|
|
|
|
60003 24 34 44 54
|
|
|
|
60004 25 35 45 55
|
|
|
|
60005 26 36 46 56
|
|
|
|
\.
|
|
|
|
|
|
|
|
COPY x from stdin WHERE f > 60003;
|
|
|
|
|
|
|
|
COPY x from stdin WHERE a = max(x.b);
|
|
|
|
|
|
|
|
COPY x from stdin WHERE a IN (SELECT 1 FROM x);
|
|
|
|
|
|
|
|
COPY x from stdin WHERE a IN (generate_series(1,5));
|
|
|
|
|
|
|
|
COPY x from stdin WHERE a = row_number() over(b);
|
|
|
|
|
|
|
|
|
2002-08-02 20:15:10 +02:00
|
|
|
-- check results of copy in
|
|
|
|
SELECT * FROM x;
|
|
|
|
|
|
|
|
-- check copy out
|
2002-07-18 06:45:51 +02:00
|
|
|
COPY x TO stdout;
|
2002-07-30 18:55:06 +02:00
|
|
|
COPY x (c, e) TO stdout;
|
2002-08-02 20:15:10 +02:00
|
|
|
COPY x (b, e) TO stdout WITH NULL 'I''m null';
|
|
|
|
|
2009-06-14 02:00:24 +02:00
|
|
|
CREATE TEMP TABLE y (
|
2004-06-10 01:39:24 +02:00
|
|
|
col1 text,
|
|
|
|
col2 text
|
|
|
|
);
|
|
|
|
|
2005-06-26 05:04:37 +02:00
|
|
|
INSERT INTO y VALUES ('Jackson, Sam', E'\\h');
|
|
|
|
INSERT INTO y VALUES ('It is "perfect".',E'\t');
|
2004-06-10 01:39:24 +02:00
|
|
|
INSERT INTO y VALUES ('', NULL);
|
|
|
|
|
|
|
|
COPY y TO stdout WITH CSV;
|
|
|
|
COPY y TO stdout WITH CSV QUOTE '''' DELIMITER '|';
|
2011-02-21 06:08:04 +01:00
|
|
|
COPY y TO stdout WITH CSV FORCE QUOTE col2 ESCAPE E'\\' ENCODING 'sql_ascii';
|
2009-07-25 02:07:14 +02:00
|
|
|
COPY y TO stdout WITH CSV FORCE QUOTE *;
|
2004-06-10 01:39:24 +02:00
|
|
|
|
2010-02-17 05:19:41 +01:00
|
|
|
-- Repeat above tests with new 9.0 option syntax
|
2009-09-21 22:10:21 +02:00
|
|
|
|
|
|
|
COPY y TO stdout (FORMAT CSV);
|
|
|
|
COPY y TO stdout (FORMAT CSV, QUOTE '''', DELIMITER '|');
|
|
|
|
COPY y TO stdout (FORMAT CSV, FORCE_QUOTE (col2), ESCAPE E'\\');
|
|
|
|
COPY y TO stdout (FORMAT CSV, FORCE_QUOTE *);
|
|
|
|
|
|
|
|
\copy y TO stdout (FORMAT CSV)
|
|
|
|
\copy y TO stdout (FORMAT CSV, QUOTE '''', DELIMITER '|')
|
|
|
|
\copy y TO stdout (FORMAT CSV, FORCE_QUOTE (col2), ESCAPE E'\\')
|
|
|
|
\copy y TO stdout (FORMAT CSV, FORCE_QUOTE *)
|
|
|
|
|
2005-05-13 08:33:40 +02:00
|
|
|
--test that we read consecutive LFs properly
|
|
|
|
|
|
|
|
CREATE TEMP TABLE testnl (a int, b text, c int);
|
|
|
|
|
|
|
|
COPY testnl FROM stdin CSV;
|
|
|
|
1,"a field with two LFs
|
|
|
|
|
|
|
|
inside",2
|
|
|
|
\.
|
|
|
|
|
2005-12-28 04:25:32 +01:00
|
|
|
-- test end of copy marker
|
|
|
|
CREATE TEMP TABLE testeoc (a text);
|
|
|
|
|
|
|
|
COPY testeoc FROM stdin CSV;
|
|
|
|
a\.
|
|
|
|
\.b
|
|
|
|
c\.d
|
|
|
|
"\."
|
|
|
|
\.
|
|
|
|
|
2005-12-28 16:07:02 +01:00
|
|
|
COPY testeoc TO stdout CSV;
|
2005-05-13 08:33:40 +02:00
|
|
|
|
2012-03-26 05:17:22 +02:00
|
|
|
-- test handling of nonstandard null marker that violates escaping rules
|
|
|
|
|
|
|
|
CREATE TEMP TABLE testnull(a int, b text);
|
|
|
|
INSERT INTO testnull VALUES (1, E'\\0'), (NULL, NULL);
|
|
|
|
|
|
|
|
COPY testnull TO stdout WITH NULL AS E'\\0';
|
|
|
|
|
|
|
|
COPY testnull FROM stdin WITH NULL AS E'\\0';
|
|
|
|
42 \\0
|
|
|
|
\0 \0
|
|
|
|
\.
|
|
|
|
|
|
|
|
SELECT * FROM testnull;
|
|
|
|
|
2012-12-07 14:26:52 +01:00
|
|
|
BEGIN;
|
2012-12-01 13:54:20 +01:00
|
|
|
CREATE TABLE vistest (LIKE testeoc);
|
2012-12-07 14:26:52 +01:00
|
|
|
COPY vistest FROM stdin CSV;
|
|
|
|
a0
|
|
|
|
b
|
|
|
|
\.
|
|
|
|
COMMIT;
|
|
|
|
SELECT * FROM vistest;
|
2012-12-01 13:54:20 +01:00
|
|
|
BEGIN;
|
|
|
|
TRUNCATE vistest;
|
|
|
|
COPY vistest FROM stdin CSV;
|
2012-12-02 21:52:52 +01:00
|
|
|
a1
|
2012-12-01 13:54:20 +01:00
|
|
|
b
|
|
|
|
\.
|
|
|
|
SELECT * FROM vistest;
|
|
|
|
SAVEPOINT s1;
|
|
|
|
TRUNCATE vistest;
|
|
|
|
COPY vistest FROM stdin CSV;
|
2012-12-02 21:52:52 +01:00
|
|
|
d1
|
2012-12-01 13:54:20 +01:00
|
|
|
e
|
|
|
|
\.
|
|
|
|
SELECT * FROM vistest;
|
|
|
|
COMMIT;
|
2012-12-02 21:52:52 +01:00
|
|
|
SELECT * FROM vistest;
|
2012-12-01 13:54:20 +01:00
|
|
|
|
|
|
|
BEGIN;
|
|
|
|
TRUNCATE vistest;
|
|
|
|
COPY vistest FROM stdin CSV FREEZE;
|
2012-12-02 21:52:52 +01:00
|
|
|
a2
|
2012-12-01 13:54:20 +01:00
|
|
|
b
|
|
|
|
\.
|
|
|
|
SELECT * FROM vistest;
|
|
|
|
SAVEPOINT s1;
|
|
|
|
TRUNCATE vistest;
|
|
|
|
COPY vistest FROM stdin CSV FREEZE;
|
2012-12-02 21:52:52 +01:00
|
|
|
d2
|
2012-12-01 13:54:20 +01:00
|
|
|
e
|
|
|
|
\.
|
|
|
|
SELECT * FROM vistest;
|
|
|
|
COMMIT;
|
2012-12-02 21:52:52 +01:00
|
|
|
SELECT * FROM vistest;
|
|
|
|
|
2012-12-01 13:54:20 +01:00
|
|
|
BEGIN;
|
|
|
|
TRUNCATE vistest;
|
|
|
|
COPY vistest FROM stdin CSV FREEZE;
|
|
|
|
x
|
|
|
|
y
|
|
|
|
\.
|
|
|
|
SELECT * FROM vistest;
|
|
|
|
COMMIT;
|
|
|
|
TRUNCATE vistest;
|
|
|
|
COPY vistest FROM stdin CSV FREEZE;
|
|
|
|
p
|
|
|
|
g
|
|
|
|
\.
|
|
|
|
BEGIN;
|
2013-01-26 19:33:24 +01:00
|
|
|
TRUNCATE vistest;
|
|
|
|
SAVEPOINT s1;
|
|
|
|
COPY vistest FROM stdin CSV FREEZE;
|
|
|
|
m
|
|
|
|
k
|
|
|
|
\.
|
|
|
|
COMMIT;
|
|
|
|
BEGIN;
|
2012-12-01 13:54:20 +01:00
|
|
|
INSERT INTO vistest VALUES ('z');
|
|
|
|
SAVEPOINT s1;
|
|
|
|
TRUNCATE vistest;
|
|
|
|
ROLLBACK TO SAVEPOINT s1;
|
|
|
|
COPY vistest FROM stdin CSV FREEZE;
|
2012-12-02 21:52:52 +01:00
|
|
|
d3
|
2012-12-01 13:54:20 +01:00
|
|
|
e
|
|
|
|
\.
|
|
|
|
COMMIT;
|
|
|
|
CREATE FUNCTION truncate_in_subxact() RETURNS VOID AS
|
|
|
|
$$
|
|
|
|
BEGIN
|
2012-12-02 21:52:52 +01:00
|
|
|
TRUNCATE vistest;
|
2012-12-01 13:54:20 +01:00
|
|
|
EXCEPTION
|
|
|
|
WHEN OTHERS THEN
|
2012-12-02 21:52:52 +01:00
|
|
|
INSERT INTO vistest VALUES ('subxact failure');
|
2012-12-01 13:54:20 +01:00
|
|
|
END;
|
|
|
|
$$ language plpgsql;
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO vistest VALUES ('z');
|
|
|
|
SELECT truncate_in_subxact();
|
|
|
|
COPY vistest FROM stdin CSV FREEZE;
|
2012-12-02 21:52:52 +01:00
|
|
|
d4
|
2012-12-01 13:54:20 +01:00
|
|
|
e
|
|
|
|
\.
|
|
|
|
SELECT * FROM vistest;
|
|
|
|
COMMIT;
|
|
|
|
SELECT * FROM vistest;
|
2014-03-04 23:31:59 +01:00
|
|
|
-- Test FORCE_NOT_NULL and FORCE_NULL options
|
|
|
|
CREATE TEMP TABLE forcetest (
|
|
|
|
a INT NOT NULL,
|
|
|
|
b TEXT NOT NULL,
|
|
|
|
c TEXT,
|
|
|
|
d TEXT,
|
|
|
|
e TEXT
|
|
|
|
);
|
|
|
|
\pset null NULL
|
2014-04-22 22:06:37 +02:00
|
|
|
-- should succeed with no effect ("b" remains an empty string, "c" remains NULL)
|
2014-03-04 23:31:59 +01:00
|
|
|
BEGIN;
|
|
|
|
COPY forcetest (a, b, c) FROM STDIN WITH (FORMAT csv, FORCE_NOT_NULL(b), FORCE_NULL(c));
|
|
|
|
1,,""
|
|
|
|
\.
|
|
|
|
COMMIT;
|
|
|
|
SELECT b, c FROM forcetest WHERE a = 1;
|
2014-04-22 22:06:37 +02:00
|
|
|
-- should succeed, FORCE_NULL and FORCE_NOT_NULL can be both specified
|
2014-03-04 23:31:59 +01:00
|
|
|
BEGIN;
|
2014-04-22 22:06:37 +02:00
|
|
|
COPY forcetest (a, b, c, d) FROM STDIN WITH (FORMAT csv, FORCE_NOT_NULL(c,d), FORCE_NULL(c,d));
|
|
|
|
2,'a',,""
|
2014-03-04 23:31:59 +01:00
|
|
|
\.
|
|
|
|
COMMIT;
|
2014-04-22 22:06:37 +02:00
|
|
|
SELECT c, d FROM forcetest WHERE a = 2;
|
2014-03-04 23:31:59 +01:00
|
|
|
-- should fail with not-null constraint violation
|
|
|
|
BEGIN;
|
|
|
|
COPY forcetest (a, b, c) FROM STDIN WITH (FORMAT csv, FORCE_NULL(b), FORCE_NOT_NULL(c));
|
|
|
|
3,,""
|
|
|
|
\.
|
|
|
|
ROLLBACK;
|
|
|
|
-- should fail with "not referenced by COPY" error
|
|
|
|
BEGIN;
|
|
|
|
COPY forcetest (d, e) FROM STDIN WITH (FORMAT csv, FORCE_NOT_NULL(b));
|
|
|
|
ROLLBACK;
|
|
|
|
-- should fail with "not referenced by COPY" error
|
|
|
|
BEGIN;
|
|
|
|
COPY forcetest (d, e) FROM STDIN WITH (FORMAT csv, FORCE_NULL(b));
|
|
|
|
ROLLBACK;
|
2023-09-30 18:34:41 +02:00
|
|
|
-- should succeed with no effect ("b" remains an empty string, "c" remains NULL)
|
|
|
|
BEGIN;
|
|
|
|
COPY forcetest (a, b, c) FROM STDIN WITH (FORMAT csv, FORCE_NOT_NULL *, FORCE_NULL *);
|
|
|
|
4,,""
|
|
|
|
\.
|
|
|
|
COMMIT;
|
|
|
|
SELECT b, c FROM forcetest WHERE a = 4;
|
|
|
|
-- should succeed with effect ("b" remains an empty string)
|
|
|
|
BEGIN;
|
|
|
|
COPY forcetest (a, b, c) FROM STDIN WITH (FORMAT csv, FORCE_NOT_NULL *);
|
|
|
|
5,,""
|
|
|
|
\.
|
|
|
|
COMMIT;
|
|
|
|
SELECT b, c FROM forcetest WHERE a = 5;
|
|
|
|
-- should succeed with effect ("c" remains NULL)
|
|
|
|
BEGIN;
|
|
|
|
COPY forcetest (a, b, c) FROM STDIN WITH (FORMAT csv, FORCE_NULL *);
|
|
|
|
6,"b",""
|
|
|
|
\.
|
|
|
|
COMMIT;
|
|
|
|
SELECT b, c FROM forcetest WHERE a = 6;
|
|
|
|
-- should fail with "conflicting or redundant options" error
|
|
|
|
BEGIN;
|
|
|
|
COPY forcetest (a, b, c) FROM STDIN WITH (FORMAT csv, FORCE_NOT_NULL *, FORCE_NOT_NULL(b));
|
|
|
|
ROLLBACK;
|
|
|
|
-- should fail with "conflicting or redundant options" error
|
|
|
|
BEGIN;
|
|
|
|
COPY forcetest (a, b, c) FROM STDIN WITH (FORMAT csv, FORCE_NULL *, FORCE_NULL(b));
|
|
|
|
ROLLBACK;
|
|
|
|
|
2014-03-04 23:31:59 +01:00
|
|
|
\pset null ''
|
2015-02-16 05:26:45 +01:00
|
|
|
|
|
|
|
-- test case with whole-row Var in a check constraint
|
|
|
|
create table check_con_tbl (f1 int);
|
|
|
|
create function check_con_function(check_con_tbl) returns bool as $$
|
|
|
|
begin
|
|
|
|
raise notice 'input = %', row_to_json($1);
|
|
|
|
return $1.f1 > 0;
|
|
|
|
end $$ language plpgsql immutable;
|
|
|
|
alter table check_con_tbl add check (check_con_function(check_con_tbl.*));
|
|
|
|
\d+ check_con_tbl
|
|
|
|
copy check_con_tbl from stdin;
|
|
|
|
1
|
|
|
|
\N
|
|
|
|
\.
|
|
|
|
copy check_con_tbl from stdin;
|
|
|
|
0
|
|
|
|
\.
|
|
|
|
select * from check_con_tbl;
|
|
|
|
|
2016-10-03 22:22:57 +02:00
|
|
|
-- test with RLS enabled.
|
|
|
|
CREATE ROLE regress_rls_copy_user;
|
|
|
|
CREATE ROLE regress_rls_copy_user_colperms;
|
|
|
|
CREATE TABLE rls_t1 (a int, b int, c int);
|
|
|
|
|
|
|
|
COPY rls_t1 (a, b, c) from stdin;
|
|
|
|
1 4 1
|
|
|
|
2 3 2
|
|
|
|
3 2 3
|
|
|
|
4 1 4
|
|
|
|
\.
|
|
|
|
|
|
|
|
CREATE POLICY p1 ON rls_t1 FOR SELECT USING (a % 2 = 0);
|
|
|
|
ALTER TABLE rls_t1 ENABLE ROW LEVEL SECURITY;
|
|
|
|
ALTER TABLE rls_t1 FORCE ROW LEVEL SECURITY;
|
|
|
|
|
|
|
|
GRANT SELECT ON TABLE rls_t1 TO regress_rls_copy_user;
|
|
|
|
GRANT SELECT (a, b) ON TABLE rls_t1 TO regress_rls_copy_user_colperms;
|
|
|
|
|
|
|
|
-- all columns
|
|
|
|
COPY rls_t1 TO stdout;
|
|
|
|
COPY rls_t1 (a, b, c) TO stdout;
|
|
|
|
|
|
|
|
-- subset of columns
|
|
|
|
COPY rls_t1 (a) TO stdout;
|
|
|
|
COPY rls_t1 (a, b) TO stdout;
|
|
|
|
|
|
|
|
-- column reordering
|
|
|
|
COPY rls_t1 (b, a) TO stdout;
|
|
|
|
|
|
|
|
SET SESSION AUTHORIZATION regress_rls_copy_user;
|
|
|
|
|
|
|
|
-- all columns
|
|
|
|
COPY rls_t1 TO stdout;
|
|
|
|
COPY rls_t1 (a, b, c) TO stdout;
|
|
|
|
|
|
|
|
-- subset of columns
|
|
|
|
COPY rls_t1 (a) TO stdout;
|
|
|
|
COPY rls_t1 (a, b) TO stdout;
|
|
|
|
|
|
|
|
-- column reordering
|
|
|
|
COPY rls_t1 (b, a) TO stdout;
|
|
|
|
|
|
|
|
RESET SESSION AUTHORIZATION;
|
|
|
|
|
|
|
|
SET SESSION AUTHORIZATION regress_rls_copy_user_colperms;
|
|
|
|
|
|
|
|
-- attempt all columns (should fail)
|
|
|
|
COPY rls_t1 TO stdout;
|
|
|
|
COPY rls_t1 (a, b, c) TO stdout;
|
|
|
|
|
|
|
|
-- try to copy column with no privileges (should fail)
|
|
|
|
COPY rls_t1 (c) TO stdout;
|
|
|
|
|
|
|
|
-- subset of columns (should succeed)
|
|
|
|
COPY rls_t1 (a) TO stdout;
|
|
|
|
COPY rls_t1 (a, b) TO stdout;
|
|
|
|
|
|
|
|
RESET SESSION AUTHORIZATION;
|
|
|
|
|
2016-11-10 20:13:43 +01:00
|
|
|
-- test with INSTEAD OF INSERT trigger on a view
|
|
|
|
CREATE TABLE instead_of_insert_tbl(id serial, name text);
|
|
|
|
CREATE VIEW instead_of_insert_tbl_view AS SELECT ''::text AS str;
|
|
|
|
|
|
|
|
COPY instead_of_insert_tbl_view FROM stdin; -- fail
|
|
|
|
test1
|
|
|
|
\.
|
|
|
|
|
|
|
|
CREATE FUNCTION fun_instead_of_insert_tbl() RETURNS trigger AS $$
|
|
|
|
BEGIN
|
|
|
|
INSERT INTO instead_of_insert_tbl (name) VALUES (NEW.str);
|
|
|
|
RETURN NULL;
|
|
|
|
END;
|
|
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
CREATE TRIGGER trig_instead_of_insert_tbl_view
|
|
|
|
INSTEAD OF INSERT ON instead_of_insert_tbl_view
|
|
|
|
FOR EACH ROW EXECUTE PROCEDURE fun_instead_of_insert_tbl();
|
|
|
|
|
|
|
|
COPY instead_of_insert_tbl_view FROM stdin;
|
|
|
|
test1
|
|
|
|
\.
|
|
|
|
|
|
|
|
SELECT * FROM instead_of_insert_tbl;
|
|
|
|
|
2018-12-23 08:42:22 +01:00
|
|
|
-- Test of COPY optimization with view using INSTEAD OF INSERT
|
|
|
|
-- trigger when relation is created in the same transaction as
|
|
|
|
-- when COPY is executed.
|
|
|
|
BEGIN;
|
|
|
|
CREATE VIEW instead_of_insert_tbl_view_2 as select ''::text as str;
|
|
|
|
CREATE TRIGGER trig_instead_of_insert_tbl_view_2
|
|
|
|
INSTEAD OF INSERT ON instead_of_insert_tbl_view_2
|
|
|
|
FOR EACH ROW EXECUTE PROCEDURE fun_instead_of_insert_tbl();
|
|
|
|
|
|
|
|
COPY instead_of_insert_tbl_view_2 FROM stdin;
|
|
|
|
test1
|
|
|
|
\.
|
|
|
|
|
|
|
|
SELECT * FROM instead_of_insert_tbl;
|
|
|
|
COMMIT;
|
2016-11-10 20:13:43 +01:00
|
|
|
|
2024-01-19 14:08:40 +01:00
|
|
|
-- tests for on_error option
|
Add new COPY option SAVE_ERROR_TO
Currently, when source data contains unexpected data regarding data type or
range, the entire COPY fails. However, in some cases, such data can be ignored
and just copying normal data is preferable.
This commit adds a new option SAVE_ERROR_TO, which specifies where to save the
error information. When this option is specified, COPY skips soft errors and
continues copying.
Currently, SAVE_ERROR_TO only supports "none". This indicates error information
is not saved and COPY just skips the unexpected data and continues running.
Later works are expected to add more choices, such as 'log' and 'table'.
Author: Damir Belyalov, Atsushi Torikoshi, Alex Shulgin, Jian He
Discussion: https://postgr.es/m/87k31ftoe0.fsf_-_%40commandprompt.com
Reviewed-by: Pavel Stehule, Andres Freund, Tom Lane, Daniel Gustafsson,
Reviewed-by: Alena Rybakina, Andy Fan, Andrei Lepikhov, Masahiko Sawada
Reviewed-by: Vignesh C, Atsushi Torikoshi
2024-01-16 22:08:53 +01:00
|
|
|
CREATE TABLE check_ign_err (n int, m int[], k int);
|
2024-01-19 14:08:40 +01:00
|
|
|
COPY check_ign_err FROM STDIN WITH (on_error stop);
|
Add new COPY option SAVE_ERROR_TO
Currently, when source data contains unexpected data regarding data type or
range, the entire COPY fails. However, in some cases, such data can be ignored
and just copying normal data is preferable.
This commit adds a new option SAVE_ERROR_TO, which specifies where to save the
error information. When this option is specified, COPY skips soft errors and
continues copying.
Currently, SAVE_ERROR_TO only supports "none". This indicates error information
is not saved and COPY just skips the unexpected data and continues running.
Later works are expected to add more choices, such as 'log' and 'table'.
Author: Damir Belyalov, Atsushi Torikoshi, Alex Shulgin, Jian He
Discussion: https://postgr.es/m/87k31ftoe0.fsf_-_%40commandprompt.com
Reviewed-by: Pavel Stehule, Andres Freund, Tom Lane, Daniel Gustafsson,
Reviewed-by: Alena Rybakina, Andy Fan, Andrei Lepikhov, Masahiko Sawada
Reviewed-by: Vignesh C, Atsushi Torikoshi
2024-01-16 22:08:53 +01:00
|
|
|
1 {1} 1
|
|
|
|
a {2} 2
|
|
|
|
3 {3} 3333333333
|
|
|
|
4 {a, 4} 4
|
|
|
|
|
|
|
|
5 {5} 5
|
|
|
|
\.
|
2024-01-19 14:08:40 +01:00
|
|
|
COPY check_ign_err FROM STDIN WITH (on_error ignore);
|
Add new COPY option SAVE_ERROR_TO
Currently, when source data contains unexpected data regarding data type or
range, the entire COPY fails. However, in some cases, such data can be ignored
and just copying normal data is preferable.
This commit adds a new option SAVE_ERROR_TO, which specifies where to save the
error information. When this option is specified, COPY skips soft errors and
continues copying.
Currently, SAVE_ERROR_TO only supports "none". This indicates error information
is not saved and COPY just skips the unexpected data and continues running.
Later works are expected to add more choices, such as 'log' and 'table'.
Author: Damir Belyalov, Atsushi Torikoshi, Alex Shulgin, Jian He
Discussion: https://postgr.es/m/87k31ftoe0.fsf_-_%40commandprompt.com
Reviewed-by: Pavel Stehule, Andres Freund, Tom Lane, Daniel Gustafsson,
Reviewed-by: Alena Rybakina, Andy Fan, Andrei Lepikhov, Masahiko Sawada
Reviewed-by: Vignesh C, Atsushi Torikoshi
2024-01-16 22:08:53 +01:00
|
|
|
1 {1} 1
|
|
|
|
a {2} 2
|
|
|
|
3 {3} 3333333333
|
|
|
|
4 {a, 4} 4
|
|
|
|
|
|
|
|
5 {5} 5
|
|
|
|
\.
|
|
|
|
SELECT * FROM check_ign_err;
|
|
|
|
|
|
|
|
-- test datatype error that can't be handled as soft: should fail
|
|
|
|
CREATE TABLE hard_err(foo widget);
|
2024-01-19 14:08:40 +01:00
|
|
|
COPY hard_err FROM STDIN WITH (on_error ignore);
|
Add new COPY option SAVE_ERROR_TO
Currently, when source data contains unexpected data regarding data type or
range, the entire COPY fails. However, in some cases, such data can be ignored
and just copying normal data is preferable.
This commit adds a new option SAVE_ERROR_TO, which specifies where to save the
error information. When this option is specified, COPY skips soft errors and
continues copying.
Currently, SAVE_ERROR_TO only supports "none". This indicates error information
is not saved and COPY just skips the unexpected data and continues running.
Later works are expected to add more choices, such as 'log' and 'table'.
Author: Damir Belyalov, Atsushi Torikoshi, Alex Shulgin, Jian He
Discussion: https://postgr.es/m/87k31ftoe0.fsf_-_%40commandprompt.com
Reviewed-by: Pavel Stehule, Andres Freund, Tom Lane, Daniel Gustafsson,
Reviewed-by: Alena Rybakina, Andy Fan, Andrei Lepikhov, Masahiko Sawada
Reviewed-by: Vignesh C, Atsushi Torikoshi
2024-01-16 22:08:53 +01:00
|
|
|
1
|
|
|
|
\.
|
|
|
|
|
|
|
|
-- test missing data: should fail
|
2024-01-19 14:08:40 +01:00
|
|
|
COPY check_ign_err FROM STDIN WITH (on_error ignore);
|
Add new COPY option SAVE_ERROR_TO
Currently, when source data contains unexpected data regarding data type or
range, the entire COPY fails. However, in some cases, such data can be ignored
and just copying normal data is preferable.
This commit adds a new option SAVE_ERROR_TO, which specifies where to save the
error information. When this option is specified, COPY skips soft errors and
continues copying.
Currently, SAVE_ERROR_TO only supports "none". This indicates error information
is not saved and COPY just skips the unexpected data and continues running.
Later works are expected to add more choices, such as 'log' and 'table'.
Author: Damir Belyalov, Atsushi Torikoshi, Alex Shulgin, Jian He
Discussion: https://postgr.es/m/87k31ftoe0.fsf_-_%40commandprompt.com
Reviewed-by: Pavel Stehule, Andres Freund, Tom Lane, Daniel Gustafsson,
Reviewed-by: Alena Rybakina, Andy Fan, Andrei Lepikhov, Masahiko Sawada
Reviewed-by: Vignesh C, Atsushi Torikoshi
2024-01-16 22:08:53 +01:00
|
|
|
1 {1}
|
|
|
|
\.
|
|
|
|
|
|
|
|
-- test extra data: should fail
|
2024-01-19 14:08:40 +01:00
|
|
|
COPY check_ign_err FROM STDIN WITH (on_error ignore);
|
Add new COPY option SAVE_ERROR_TO
Currently, when source data contains unexpected data regarding data type or
range, the entire COPY fails. However, in some cases, such data can be ignored
and just copying normal data is preferable.
This commit adds a new option SAVE_ERROR_TO, which specifies where to save the
error information. When this option is specified, COPY skips soft errors and
continues copying.
Currently, SAVE_ERROR_TO only supports "none". This indicates error information
is not saved and COPY just skips the unexpected data and continues running.
Later works are expected to add more choices, such as 'log' and 'table'.
Author: Damir Belyalov, Atsushi Torikoshi, Alex Shulgin, Jian He
Discussion: https://postgr.es/m/87k31ftoe0.fsf_-_%40commandprompt.com
Reviewed-by: Pavel Stehule, Andres Freund, Tom Lane, Daniel Gustafsson,
Reviewed-by: Alena Rybakina, Andy Fan, Andrei Lepikhov, Masahiko Sawada
Reviewed-by: Vignesh C, Atsushi Torikoshi
2024-01-16 22:08:53 +01:00
|
|
|
1 {1} 3 abc
|
|
|
|
\.
|
|
|
|
|
2016-11-10 20:13:43 +01:00
|
|
|
-- clean up
|
2014-03-04 23:31:59 +01:00
|
|
|
DROP TABLE forcetest;
|
2012-12-01 13:54:20 +01:00
|
|
|
DROP TABLE vistest;
|
|
|
|
DROP FUNCTION truncate_in_subxact();
|
2004-06-10 19:56:03 +02:00
|
|
|
DROP TABLE x, y;
|
2016-10-03 22:22:57 +02:00
|
|
|
DROP TABLE rls_t1 CASCADE;
|
|
|
|
DROP ROLE regress_rls_copy_user;
|
|
|
|
DROP ROLE regress_rls_copy_user_colperms;
|
2002-07-18 06:45:51 +02:00
|
|
|
DROP FUNCTION fn_x_before();
|
|
|
|
DROP FUNCTION fn_x_after();
|
2016-11-10 20:13:43 +01:00
|
|
|
DROP TABLE instead_of_insert_tbl;
|
|
|
|
DROP VIEW instead_of_insert_tbl_view;
|
2018-12-23 08:42:22 +01:00
|
|
|
DROP VIEW instead_of_insert_tbl_view_2;
|
2016-11-10 20:13:43 +01:00
|
|
|
DROP FUNCTION fun_instead_of_insert_tbl();
|
Add new COPY option SAVE_ERROR_TO
Currently, when source data contains unexpected data regarding data type or
range, the entire COPY fails. However, in some cases, such data can be ignored
and just copying normal data is preferable.
This commit adds a new option SAVE_ERROR_TO, which specifies where to save the
error information. When this option is specified, COPY skips soft errors and
continues copying.
Currently, SAVE_ERROR_TO only supports "none". This indicates error information
is not saved and COPY just skips the unexpected data and continues running.
Later works are expected to add more choices, such as 'log' and 'table'.
Author: Damir Belyalov, Atsushi Torikoshi, Alex Shulgin, Jian He
Discussion: https://postgr.es/m/87k31ftoe0.fsf_-_%40commandprompt.com
Reviewed-by: Pavel Stehule, Andres Freund, Tom Lane, Daniel Gustafsson,
Reviewed-by: Alena Rybakina, Andy Fan, Andrei Lepikhov, Masahiko Sawada
Reviewed-by: Vignesh C, Atsushi Torikoshi
2024-01-16 22:08:53 +01:00
|
|
|
DROP TABLE check_ign_err;
|
|
|
|
DROP TABLE hard_err;
|
2023-03-13 15:01:56 +01:00
|
|
|
|
|
|
|
--
|
|
|
|
-- COPY FROM ... DEFAULT
|
|
|
|
--
|
|
|
|
|
|
|
|
create temp table copy_default (
|
|
|
|
id integer primary key,
|
|
|
|
text_value text not null default 'test',
|
|
|
|
ts_value timestamp without time zone not null default '2022-07-05'
|
|
|
|
);
|
|
|
|
|
|
|
|
-- if DEFAULT is not specified, then the marker will be regular data
|
|
|
|
copy copy_default from stdin;
|
|
|
|
1 value '2022-07-04'
|
|
|
|
2 \D '2022-07-05'
|
|
|
|
\.
|
|
|
|
|
|
|
|
select id, text_value, ts_value from copy_default;
|
|
|
|
|
|
|
|
truncate copy_default;
|
|
|
|
|
|
|
|
copy copy_default from stdin with (format csv);
|
|
|
|
1,value,2022-07-04
|
|
|
|
2,\D,2022-07-05
|
|
|
|
\.
|
|
|
|
|
|
|
|
select id, text_value, ts_value from copy_default;
|
|
|
|
|
|
|
|
truncate copy_default;
|
|
|
|
|
|
|
|
-- DEFAULT cannot be used in binary mode
|
|
|
|
copy copy_default from stdin with (format binary, default '\D');
|
|
|
|
|
|
|
|
-- DEFAULT cannot be new line nor carriage return
|
|
|
|
copy copy_default from stdin with (default E'\n');
|
|
|
|
copy copy_default from stdin with (default E'\r');
|
|
|
|
|
|
|
|
-- DELIMITER cannot appear in DEFAULT spec
|
|
|
|
copy copy_default from stdin with (delimiter ';', default 'test;test');
|
|
|
|
|
|
|
|
-- CSV quote cannot appear in DEFAULT spec
|
|
|
|
copy copy_default from stdin with (format csv, quote '"', default 'test"test');
|
|
|
|
|
|
|
|
-- NULL and DEFAULT spec must be different
|
|
|
|
copy copy_default from stdin with (default '\N');
|
|
|
|
|
|
|
|
-- cannot use DEFAULT marker in column that has no DEFAULT value
|
|
|
|
copy copy_default from stdin with (default '\D');
|
|
|
|
\D value '2022-07-04'
|
|
|
|
2 \D '2022-07-05'
|
|
|
|
\.
|
|
|
|
|
|
|
|
copy copy_default from stdin with (format csv, default '\D');
|
|
|
|
\D,value,2022-07-04
|
|
|
|
2,\D,2022-07-05
|
|
|
|
\.
|
|
|
|
|
|
|
|
-- The DEFAULT marker must be unquoted and unescaped or it's not recognized
|
|
|
|
copy copy_default from stdin with (default '\D');
|
|
|
|
1 \D '2022-07-04'
|
|
|
|
2 \\D '2022-07-04'
|
|
|
|
3 "\D" '2022-07-04'
|
|
|
|
\.
|
|
|
|
|
|
|
|
select id, text_value, ts_value from copy_default;
|
|
|
|
|
|
|
|
truncate copy_default;
|
|
|
|
|
|
|
|
copy copy_default from stdin with (format csv, default '\D');
|
|
|
|
1,\D,2022-07-04
|
|
|
|
2,\\D,2022-07-04
|
|
|
|
3,"\D",2022-07-04
|
|
|
|
\.
|
|
|
|
|
|
|
|
select id, text_value, ts_value from copy_default;
|
|
|
|
|
|
|
|
truncate copy_default;
|
|
|
|
|
|
|
|
-- successful usage of DEFAULT option in COPY
|
|
|
|
copy copy_default from stdin with (default '\D');
|
|
|
|
1 value '2022-07-04'
|
|
|
|
2 \D '2022-07-03'
|
|
|
|
3 \D \D
|
|
|
|
\.
|
|
|
|
|
|
|
|
select id, text_value, ts_value from copy_default;
|
|
|
|
|
|
|
|
truncate copy_default;
|
|
|
|
|
|
|
|
copy copy_default from stdin with (format csv, default '\D');
|
|
|
|
1,value,2022-07-04
|
|
|
|
2,\D,2022-07-03
|
|
|
|
3,\D,\D
|
|
|
|
\.
|
|
|
|
|
|
|
|
select id, text_value, ts_value from copy_default;
|
|
|
|
|
|
|
|
truncate copy_default;
|
|
|
|
|
|
|
|
-- DEFAULT cannot be used in COPY TO
|
|
|
|
copy (select 1 as test) TO stdout with (default '\D');
|