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-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-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;
|
|
|
|
COPY x (b, d) from stdin;
|
|
|
|
COPY x (b, d) from stdin;
|
|
|
|
COPY x (a, b, c, d, e) from stdin;
|
|
|
|
-- non-existent column in column list: should fail
|
|
|
|
COPY x (xyz) from stdin;
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: column "xyz" of relation "x" does not exist
|
2020-10-05 02:43:17 +02:00
|
|
|
-- redundant options
|
|
|
|
COPY x from stdin (format CSV, FORMAT CSV);
|
|
|
|
ERROR: conflicting or redundant options
|
|
|
|
LINE 1: COPY x from stdin (format CSV, FORMAT CSV);
|
|
|
|
^
|
|
|
|
COPY x from stdin (freeze off, freeze on);
|
|
|
|
ERROR: conflicting or redundant options
|
|
|
|
LINE 1: COPY x from stdin (freeze off, freeze on);
|
|
|
|
^
|
|
|
|
COPY x from stdin (delimiter ',', delimiter ',');
|
|
|
|
ERROR: conflicting or redundant options
|
|
|
|
LINE 1: COPY x from stdin (delimiter ',', delimiter ',');
|
|
|
|
^
|
|
|
|
COPY x from stdin (null ' ', null ' ');
|
|
|
|
ERROR: conflicting or redundant options
|
|
|
|
LINE 1: COPY x from stdin (null ' ', null ' ');
|
|
|
|
^
|
|
|
|
COPY x from stdin (header off, header on);
|
|
|
|
ERROR: conflicting or redundant options
|
|
|
|
LINE 1: COPY x from stdin (header off, header on);
|
|
|
|
^
|
|
|
|
COPY x from stdin (quote ':', quote ':');
|
|
|
|
ERROR: conflicting or redundant options
|
|
|
|
LINE 1: COPY x from stdin (quote ':', quote ':');
|
|
|
|
^
|
|
|
|
COPY x from stdin (escape ':', escape ':');
|
|
|
|
ERROR: conflicting or redundant options
|
|
|
|
LINE 1: COPY x from stdin (escape ':', escape ':');
|
|
|
|
^
|
|
|
|
COPY x from stdin (force_quote (a), force_quote *);
|
|
|
|
ERROR: conflicting or redundant options
|
|
|
|
LINE 1: COPY x from stdin (force_quote (a), force_quote *);
|
|
|
|
^
|
|
|
|
COPY x from stdin (force_not_null (a), force_not_null (b));
|
|
|
|
ERROR: conflicting or redundant options
|
|
|
|
LINE 1: COPY x from stdin (force_not_null (a), force_not_null (b));
|
|
|
|
^
|
|
|
|
COPY x from stdin (force_null (a), force_null (b));
|
|
|
|
ERROR: conflicting or redundant options
|
Improve reporting of "conflicting or redundant options" errors.
When reporting "conflicting or redundant options" errors, try to
ensure that errposition() is used, to help the user identify the
offending option.
Formerly, errposition() was invoked in less than 60% of cases. This
patch raises that to over 90%, but there remain a few places where the
ParseState is not readily available. Using errdetail() might improve
the error in such cases, but that is left as a task for the future.
Additionally, since this error is thrown from over 100 places in the
codebase, introduce a dedicated function to throw it, reducing code
duplication.
Extracted from a slightly larger patch by Vignesh C. Reviewed by
Bharath Rupireddy, Alvaro Herrera, Dilip Kumar, Hou Zhijie, Peter
Smith, Daniel Gustafsson, Julien Rouhaud and me.
Discussion: https://postgr.es/m/CALDaNm33FFSS5tVyvmkoK2cCMuDVxcui=gFrjti9ROfynqSAGA@mail.gmail.com
2021-07-15 09:49:45 +02:00
|
|
|
LINE 1: COPY x from stdin (force_null (a), force_null (b));
|
|
|
|
^
|
2020-10-05 02:43:17 +02:00
|
|
|
COPY x from stdin (convert_selectively (a), convert_selectively (b));
|
|
|
|
ERROR: conflicting or redundant options
|
|
|
|
LINE 1: COPY x from stdin (convert_selectively (a), convert_selectiv...
|
|
|
|
^
|
|
|
|
COPY x from stdin (encoding 'sql_ascii', encoding 'sql_ascii');
|
|
|
|
ERROR: conflicting or redundant options
|
|
|
|
LINE 1: COPY x from stdin (encoding 'sql_ascii', encoding 'sql_ascii...
|
|
|
|
^
|
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
|
|
|
COPY x from stdin (save_error_to none,save_error_to none);
|
|
|
|
ERROR: conflicting or redundant options
|
|
|
|
LINE 1: COPY x from stdin (save_error_to none,save_error_to none);
|
|
|
|
^
|
2022-11-02 01:57:54 +01:00
|
|
|
-- incorrect options
|
|
|
|
COPY x to stdin (format BINARY, delimiter ',');
|
|
|
|
ERROR: cannot specify DELIMITER in BINARY mode
|
|
|
|
COPY x to stdin (format BINARY, null 'x');
|
|
|
|
ERROR: cannot specify NULL in BINARY mode
|
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
|
|
|
COPY x from stdin (format BINARY, save_error_to none);
|
|
|
|
ERROR: cannot specify SAVE_ERROR_TO in BINARY mode
|
|
|
|
COPY x to stdin (save_error_to none);
|
|
|
|
ERROR: COPY SAVE_ERROR_TO cannot be used with COPY TO
|
|
|
|
LINE 1: COPY x to stdin (save_error_to none);
|
|
|
|
^
|
2022-11-02 01:57:54 +01:00
|
|
|
COPY x to stdin (format TEXT, force_quote(a));
|
2023-11-13 18:53:03 +01:00
|
|
|
ERROR: COPY FORCE_QUOTE requires CSV mode
|
2022-11-02 01:57:54 +01:00
|
|
|
COPY x from stdin (format CSV, force_quote(a));
|
2023-11-13 18:53:03 +01:00
|
|
|
ERROR: COPY FORCE_QUOTE cannot be used with COPY FROM
|
2022-11-02 01:57:54 +01:00
|
|
|
COPY x to stdout (format TEXT, force_not_null(a));
|
2023-11-13 18:53:03 +01:00
|
|
|
ERROR: COPY FORCE_NOT_NULL requires CSV mode
|
2022-11-02 01:57:54 +01:00
|
|
|
COPY x to stdin (format CSV, force_not_null(a));
|
2023-11-13 18:53:03 +01:00
|
|
|
ERROR: COPY FORCE_NOT_NULL cannot be used with COPY TO
|
2022-11-02 01:57:54 +01:00
|
|
|
COPY x to stdout (format TEXT, force_null(a));
|
2023-11-13 18:53:03 +01:00
|
|
|
ERROR: COPY FORCE_NULL requires CSV mode
|
2022-11-02 01:57:54 +01:00
|
|
|
COPY x to stdin (format CSV, force_null(a));
|
2023-11-13 18:53:03 +01:00
|
|
|
ERROR: COPY FORCE_NULL cannot be used with COPY TO
|
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
|
|
|
COPY x to stdin (format BINARY, save_error_to unsupported);
|
|
|
|
ERROR: COPY SAVE_ERROR_TO cannot be used with COPY TO
|
|
|
|
LINE 1: COPY x to stdin (format BINARY, save_error_to unsupported);
|
|
|
|
^
|
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;
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: column "d" specified more than once
|
2002-07-30 18:55:06 +02:00
|
|
|
-- missing data: should fail
|
|
|
|
COPY x from stdin;
|
2018-07-22 23:58:01 +02:00
|
|
|
ERROR: invalid input syntax for type integer: ""
|
2003-09-30 00:06:40 +02:00
|
|
|
CONTEXT: COPY x, line 1, column a: ""
|
2002-07-30 18:55:06 +02:00
|
|
|
COPY x from stdin;
|
2003-07-20 23:56:35 +02:00
|
|
|
ERROR: missing data for column "e"
|
2003-09-30 00:06:40 +02:00
|
|
|
CONTEXT: COPY x, line 1: "2000 230 23 23"
|
2002-07-30 18:55:06 +02:00
|
|
|
COPY x from stdin;
|
2003-07-20 23:56:35 +02:00
|
|
|
ERROR: missing data for column "e"
|
2003-09-30 00:06:40 +02:00
|
|
|
CONTEXT: COPY x, line 1: "2001 231 \N \N"
|
2002-07-30 18:55:06 +02:00
|
|
|
-- extra data: should fail
|
|
|
|
COPY x from stdin;
|
2003-07-20 23:56:35 +02:00
|
|
|
ERROR: extra data after last expected column
|
2003-09-30 00:06:40 +02:00
|
|
|
CONTEXT: COPY x, line 1: "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';
|
2003-10-10 05:46:51 +02:00
|
|
|
COPY x from stdin WITH DELIMITER AS ';' NULL AS '';
|
2011-02-21 06:08:04 +01:00
|
|
|
COPY x from stdin WITH DELIMITER AS ':' NULL AS E'\\X' ENCODING 'sql_ascii';
|
2019-01-19 23:48:16 +01:00
|
|
|
COPY x TO stdout WHERE a = 1;
|
|
|
|
ERROR: WHERE clause not allowed with COPY TO
|
|
|
|
LINE 1: COPY x TO stdout WHERE a = 1;
|
|
|
|
^
|
|
|
|
COPY x from stdin WHERE a = 50004;
|
|
|
|
COPY x from stdin WHERE a > 60003;
|
|
|
|
COPY x from stdin WHERE f > 60003;
|
|
|
|
ERROR: column "f" does not exist
|
|
|
|
LINE 1: COPY x from stdin WHERE f > 60003;
|
|
|
|
^
|
|
|
|
COPY x from stdin WHERE a = max(x.b);
|
|
|
|
ERROR: aggregate functions are not allowed in COPY FROM WHERE conditions
|
|
|
|
LINE 1: COPY x from stdin WHERE a = max(x.b);
|
|
|
|
^
|
|
|
|
COPY x from stdin WHERE a IN (SELECT 1 FROM x);
|
|
|
|
ERROR: cannot use subquery in COPY FROM WHERE condition
|
|
|
|
LINE 1: COPY x from stdin WHERE a IN (SELECT 1 FROM x);
|
|
|
|
^
|
|
|
|
COPY x from stdin WHERE a IN (generate_series(1,5));
|
|
|
|
ERROR: set-returning functions are not allowed in COPY FROM WHERE conditions
|
|
|
|
LINE 1: COPY x from stdin WHERE a IN (generate_series(1,5));
|
|
|
|
^
|
|
|
|
COPY x from stdin WHERE a = row_number() over(b);
|
|
|
|
ERROR: window functions are not allowed in COPY FROM WHERE conditions
|
|
|
|
LINE 1: 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;
|
2003-10-10 05:46:51 +02:00
|
|
|
a | b | c | d | e
|
|
|
|
-------+----+------------+--------+----------------------
|
|
|
|
9999 | | \N | NN | before trigger fired
|
|
|
|
10000 | 21 | 31 | 41 | before trigger fired
|
|
|
|
10001 | 22 | 32 | 42 | before trigger fired
|
|
|
|
10002 | 23 | 33 | 43 | before trigger fired
|
|
|
|
10003 | 24 | 34 | 44 | before trigger fired
|
|
|
|
10004 | 25 | 35 | 45 | before trigger fired
|
|
|
|
10005 | 26 | 36 | 46 | before trigger fired
|
|
|
|
6 | | 45 | 80 | before trigger fired
|
|
|
|
7 | | x | \x | before trigger fired
|
|
|
|
8 | | , | \, | before trigger fired
|
|
|
|
3000 | | c | | before trigger fired
|
|
|
|
4000 | | C | | before trigger fired
|
|
|
|
4001 | 1 | empty | | before trigger fired
|
|
|
|
4002 | 2 | null | | before trigger fired
|
|
|
|
4003 | 3 | Backslash | \ | before trigger fired
|
|
|
|
4004 | 4 | BackslashX | \X | before trigger fired
|
|
|
|
4005 | 5 | N | N | before trigger fired
|
|
|
|
4006 | 6 | BackslashN | \N | before trigger fired
|
|
|
|
4007 | 7 | XX | XX | before trigger fired
|
|
|
|
4008 | 8 | Delimiter | : | before trigger fired
|
2019-01-19 23:48:16 +01:00
|
|
|
50004 | 25 | 35 | 45 | before trigger fired
|
|
|
|
60004 | 25 | 35 | 45 | before trigger fired
|
|
|
|
60005 | 26 | 36 | 46 | before trigger fired
|
2003-10-10 05:46:51 +02:00
|
|
|
1 | 1 | stuff | test_1 | after trigger fired
|
|
|
|
2 | 2 | stuff | test_2 | after trigger fired
|
|
|
|
3 | 3 | stuff | test_3 | after trigger fired
|
|
|
|
4 | 4 | stuff | test_4 | after trigger fired
|
|
|
|
5 | 5 | stuff | test_5 | after trigger fired
|
2019-01-19 23:48:16 +01:00
|
|
|
(28 rows)
|
2002-08-02 20:15:10 +02:00
|
|
|
|
|
|
|
-- check copy out
|
2002-07-18 06:45:51 +02:00
|
|
|
COPY x TO stdout;
|
2003-10-10 05:46:51 +02:00
|
|
|
9999 \N \\N NN before trigger fired
|
2002-07-18 06:45:51 +02:00
|
|
|
10000 21 31 41 before trigger fired
|
|
|
|
10001 22 32 42 before trigger fired
|
|
|
|
10002 23 33 43 before trigger fired
|
|
|
|
10003 24 34 44 before trigger fired
|
|
|
|
10004 25 35 45 before trigger fired
|
|
|
|
10005 26 36 46 before trigger fired
|
2002-07-30 18:55:06 +02:00
|
|
|
6 \N 45 80 before trigger fired
|
2003-10-10 05:46:51 +02:00
|
|
|
7 \N x \\x before trigger fired
|
|
|
|
8 \N , \\, before trigger fired
|
|
|
|
3000 \N c \N before trigger fired
|
|
|
|
4000 \N C \N before trigger fired
|
|
|
|
4001 1 empty before trigger fired
|
|
|
|
4002 2 null \N before trigger fired
|
|
|
|
4003 3 Backslash \\ before trigger fired
|
|
|
|
4004 4 BackslashX \\X before trigger fired
|
|
|
|
4005 5 N N before trigger fired
|
|
|
|
4006 6 BackslashN \\N before trigger fired
|
|
|
|
4007 7 XX XX before trigger fired
|
|
|
|
4008 8 Delimiter : before trigger fired
|
2019-01-19 23:48:16 +01:00
|
|
|
50004 25 35 45 before trigger fired
|
|
|
|
60004 25 35 45 before trigger fired
|
|
|
|
60005 26 36 46 before trigger fired
|
2002-07-18 06:45:51 +02:00
|
|
|
1 1 stuff test_1 after trigger fired
|
|
|
|
2 2 stuff test_2 after trigger fired
|
|
|
|
3 3 stuff test_3 after trigger fired
|
|
|
|
4 4 stuff test_4 after trigger fired
|
|
|
|
5 5 stuff test_5 after trigger fired
|
2002-07-30 18:55:06 +02:00
|
|
|
COPY x (c, e) TO stdout;
|
2003-10-10 05:46:51 +02:00
|
|
|
\\N before trigger fired
|
2002-07-30 18:55:06 +02:00
|
|
|
31 before trigger fired
|
|
|
|
32 before trigger fired
|
|
|
|
33 before trigger fired
|
|
|
|
34 before trigger fired
|
|
|
|
35 before trigger fired
|
|
|
|
36 before trigger fired
|
|
|
|
45 before trigger fired
|
2003-10-10 05:46:51 +02:00
|
|
|
x before trigger fired
|
|
|
|
, before trigger fired
|
|
|
|
c before trigger fired
|
|
|
|
C before trigger fired
|
|
|
|
empty before trigger fired
|
|
|
|
null before trigger fired
|
|
|
|
Backslash before trigger fired
|
|
|
|
BackslashX before trigger fired
|
|
|
|
N before trigger fired
|
|
|
|
BackslashN before trigger fired
|
|
|
|
XX before trigger fired
|
|
|
|
Delimiter before trigger fired
|
2019-01-19 23:48:16 +01:00
|
|
|
35 before trigger fired
|
|
|
|
35 before trigger fired
|
|
|
|
36 before trigger fired
|
2002-07-30 18:55:06 +02:00
|
|
|
stuff after trigger fired
|
|
|
|
stuff after trigger fired
|
|
|
|
stuff after trigger fired
|
|
|
|
stuff after trigger fired
|
|
|
|
stuff after trigger fired
|
2002-08-02 20:15:10 +02:00
|
|
|
COPY x (b, e) TO stdout WITH NULL 'I''m null';
|
2003-10-10 05:46:51 +02:00
|
|
|
I'm null before trigger fired
|
2002-08-02 20:15:10 +02:00
|
|
|
21 before trigger fired
|
|
|
|
22 before trigger fired
|
|
|
|
23 before trigger fired
|
|
|
|
24 before trigger fired
|
|
|
|
25 before trigger fired
|
|
|
|
26 before trigger fired
|
|
|
|
I'm null before trigger fired
|
2003-10-10 05:46:51 +02:00
|
|
|
I'm null before trigger fired
|
|
|
|
I'm null before trigger fired
|
|
|
|
I'm null before trigger fired
|
|
|
|
I'm null before trigger fired
|
|
|
|
1 before trigger fired
|
|
|
|
2 before trigger fired
|
|
|
|
3 before trigger fired
|
|
|
|
4 before trigger fired
|
|
|
|
5 before trigger fired
|
|
|
|
6 before trigger fired
|
|
|
|
7 before trigger fired
|
|
|
|
8 before trigger fired
|
2019-01-19 23:48:16 +01:00
|
|
|
25 before trigger fired
|
|
|
|
25 before trigger fired
|
|
|
|
26 before trigger fired
|
2002-08-02 20:15:10 +02:00
|
|
|
1 after trigger fired
|
|
|
|
2 after trigger fired
|
|
|
|
3 after trigger fired
|
|
|
|
4 after trigger fired
|
|
|
|
5 after trigger fired
|
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;
|
|
|
|
"Jackson, Sam",\h
|
|
|
|
"It is ""perfect"".",
|
|
|
|
"",
|
|
|
|
COPY y TO stdout WITH CSV QUOTE '''' DELIMITER '|';
|
|
|
|
Jackson, Sam|\h
|
|
|
|
It is "perfect".|
|
|
|
|
''|
|
2011-02-21 06:08:04 +01:00
|
|
|
COPY y TO stdout WITH CSV FORCE QUOTE col2 ESCAPE E'\\' ENCODING 'sql_ascii';
|
2004-06-10 01:39:24 +02:00
|
|
|
"Jackson, Sam","\\h"
|
|
|
|
"It is \"perfect\"."," "
|
|
|
|
"",
|
2009-07-25 02:07:14 +02:00
|
|
|
COPY y TO stdout WITH CSV FORCE QUOTE *;
|
|
|
|
"Jackson, Sam","\h"
|
|
|
|
"It is ""perfect""."," "
|
|
|
|
"",
|
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);
|
|
|
|
"Jackson, Sam",\h
|
|
|
|
"It is ""perfect"".",
|
|
|
|
"",
|
|
|
|
COPY y TO stdout (FORMAT CSV, QUOTE '''', DELIMITER '|');
|
|
|
|
Jackson, Sam|\h
|
|
|
|
It is "perfect".|
|
|
|
|
''|
|
|
|
|
COPY y TO stdout (FORMAT CSV, FORCE_QUOTE (col2), ESCAPE E'\\');
|
|
|
|
"Jackson, Sam","\\h"
|
|
|
|
"It is \"perfect\"."," "
|
|
|
|
"",
|
|
|
|
COPY y TO stdout (FORMAT CSV, FORCE_QUOTE *);
|
|
|
|
"Jackson, Sam","\h"
|
|
|
|
"It is ""perfect""."," "
|
|
|
|
"",
|
|
|
|
\copy y TO stdout (FORMAT CSV)
|
|
|
|
"Jackson, Sam",\h
|
|
|
|
"It is ""perfect"".",
|
|
|
|
"",
|
|
|
|
\copy y TO stdout (FORMAT CSV, QUOTE '''', DELIMITER '|')
|
|
|
|
Jackson, Sam|\h
|
|
|
|
It is "perfect".|
|
|
|
|
''|
|
|
|
|
\copy y TO stdout (FORMAT CSV, FORCE_QUOTE (col2), ESCAPE E'\\')
|
|
|
|
"Jackson, Sam","\\h"
|
|
|
|
"It is \"perfect\"."," "
|
|
|
|
"",
|
|
|
|
\copy y TO stdout (FORMAT CSV, FORCE_QUOTE *)
|
|
|
|
"Jackson, Sam","\h"
|
|
|
|
"It is ""perfect""."," "
|
|
|
|
"",
|
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;
|
2005-12-28 04:25:32 +01:00
|
|
|
-- test end of copy marker
|
|
|
|
CREATE TEMP TABLE testeoc (a text);
|
|
|
|
COPY testeoc FROM stdin CSV;
|
2005-12-28 16:07:02 +01:00
|
|
|
COPY testeoc TO stdout CSV;
|
|
|
|
a\.
|
|
|
|
\.b
|
|
|
|
c\.d
|
|
|
|
"\."
|
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';
|
|
|
|
1 \\0
|
|
|
|
\0 \0
|
|
|
|
COPY testnull FROM stdin WITH NULL AS E'\\0';
|
|
|
|
SELECT * FROM testnull;
|
|
|
|
a | b
|
|
|
|
----+----
|
|
|
|
1 | \0
|
|
|
|
|
|
|
|
|
42 | \0
|
|
|
|
|
|
|
|
|
(4 rows)
|
|
|
|
|
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;
|
|
|
|
COMMIT;
|
2012-12-07 15:18:47 +01:00
|
|
|
SELECT * FROM vistest;
|
|
|
|
a
|
|
|
|
----
|
|
|
|
a0
|
|
|
|
b
|
2012-12-07 14:26:52 +01:00
|
|
|
(2 rows)
|
|
|
|
|
2012-12-01 13:54:20 +01:00
|
|
|
BEGIN;
|
|
|
|
TRUNCATE vistest;
|
|
|
|
COPY vistest FROM stdin CSV;
|
|
|
|
SELECT * FROM vistest;
|
2012-12-02 21:52:52 +01:00
|
|
|
a
|
|
|
|
----
|
|
|
|
a1
|
2012-12-01 13:54:20 +01:00
|
|
|
b
|
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
SAVEPOINT s1;
|
|
|
|
TRUNCATE vistest;
|
|
|
|
COPY vistest FROM stdin CSV;
|
|
|
|
SELECT * FROM vistest;
|
2012-12-02 21:52:52 +01:00
|
|
|
a
|
|
|
|
----
|
|
|
|
d1
|
2012-12-01 13:54:20 +01:00
|
|
|
e
|
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
COMMIT;
|
2012-12-02 21:52:52 +01:00
|
|
|
SELECT * FROM vistest;
|
|
|
|
a
|
|
|
|
----
|
|
|
|
d1
|
|
|
|
e
|
|
|
|
(2 rows)
|
|
|
|
|
2012-12-01 13:54:20 +01:00
|
|
|
BEGIN;
|
|
|
|
TRUNCATE vistest;
|
|
|
|
COPY vistest FROM stdin CSV FREEZE;
|
|
|
|
SELECT * FROM vistest;
|
2012-12-02 21:52:52 +01:00
|
|
|
a
|
|
|
|
----
|
|
|
|
a2
|
2012-12-01 13:54:20 +01:00
|
|
|
b
|
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
SAVEPOINT s1;
|
|
|
|
TRUNCATE vistest;
|
|
|
|
COPY vistest FROM stdin CSV FREEZE;
|
|
|
|
SELECT * FROM vistest;
|
2012-12-02 21:52:52 +01:00
|
|
|
a
|
|
|
|
----
|
|
|
|
d2
|
2012-12-01 13:54:20 +01:00
|
|
|
e
|
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
COMMIT;
|
2012-12-02 21:52:52 +01:00
|
|
|
SELECT * FROM vistest;
|
|
|
|
a
|
|
|
|
----
|
|
|
|
d2
|
|
|
|
e
|
|
|
|
(2 rows)
|
|
|
|
|
2012-12-01 14:46:41 +01:00
|
|
|
BEGIN;
|
2012-12-01 13:54:20 +01:00
|
|
|
TRUNCATE vistest;
|
|
|
|
COPY vistest FROM stdin CSV FREEZE;
|
|
|
|
SELECT * FROM vistest;
|
|
|
|
a
|
|
|
|
---
|
2012-12-01 14:46:41 +01:00
|
|
|
x
|
|
|
|
y
|
2012-12-01 13:54:20 +01:00
|
|
|
(2 rows)
|
|
|
|
|
2012-12-01 14:46:41 +01:00
|
|
|
COMMIT;
|
|
|
|
TRUNCATE vistest;
|
|
|
|
COPY vistest FROM stdin CSV FREEZE;
|
2019-05-17 02:40:02 +02:00
|
|
|
ERROR: cannot perform COPY FREEZE because the table was not created or truncated in the current subtransaction
|
2013-01-26 19:33:24 +01:00
|
|
|
BEGIN;
|
|
|
|
TRUNCATE vistest;
|
|
|
|
SAVEPOINT s1;
|
|
|
|
COPY vistest FROM stdin CSV FREEZE;
|
2019-05-17 02:40:02 +02:00
|
|
|
ERROR: cannot perform COPY FREEZE because the table was not created or truncated in the current subtransaction
|
2013-01-26 19:33:24 +01:00
|
|
|
COMMIT;
|
2012-12-01 13:54:20 +01:00
|
|
|
BEGIN;
|
|
|
|
INSERT INTO vistest VALUES ('z');
|
|
|
|
SAVEPOINT s1;
|
|
|
|
TRUNCATE vistest;
|
|
|
|
ROLLBACK TO SAVEPOINT s1;
|
|
|
|
COPY vistest FROM stdin CSV FREEZE;
|
2019-05-17 02:40:02 +02:00
|
|
|
ERROR: cannot perform COPY FREEZE because the table was not created or truncated in the current subtransaction
|
2012-12-01 13:54:20 +01:00
|
|
|
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();
|
|
|
|
truncate_in_subxact
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
COPY vistest FROM stdin CSV FREEZE;
|
|
|
|
SELECT * FROM vistest;
|
2012-12-02 21:52:52 +01:00
|
|
|
a
|
|
|
|
----
|
|
|
|
d4
|
2012-12-01 13:54:20 +01:00
|
|
|
e
|
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
COMMIT;
|
|
|
|
SELECT * FROM vistest;
|
2012-12-02 21:52:52 +01:00
|
|
|
a
|
|
|
|
----
|
|
|
|
d4
|
2012-12-01 13:54:20 +01:00
|
|
|
e
|
|
|
|
(2 rows)
|
|
|
|
|
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));
|
|
|
|
COMMIT;
|
|
|
|
SELECT b, c FROM forcetest WHERE a = 1;
|
|
|
|
b | c
|
|
|
|
---+------
|
|
|
|
| NULL
|
|
|
|
(1 row)
|
|
|
|
|
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));
|
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;
|
|
|
|
c | d
|
2014-03-04 23:31:59 +01:00
|
|
|
---+------
|
|
|
|
| NULL
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- 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));
|
2020-01-28 03:18:10 +01:00
|
|
|
ERROR: null value in column "b" of relation "forcetest" violates not-null constraint
|
2014-03-04 23:31:59 +01:00
|
|
|
DETAIL: Failing row contains (3, null, , null, null).
|
|
|
|
CONTEXT: COPY forcetest, line 1: "3,,"""
|
|
|
|
ROLLBACK;
|
|
|
|
-- should fail with "not referenced by COPY" error
|
|
|
|
BEGIN;
|
|
|
|
COPY forcetest (d, e) FROM STDIN WITH (FORMAT csv, FORCE_NOT_NULL(b));
|
2015-11-05 03:01:26 +01:00
|
|
|
ERROR: FORCE_NOT_NULL column "b" not referenced by COPY
|
2014-03-04 23:31:59 +01:00
|
|
|
ROLLBACK;
|
|
|
|
-- should fail with "not referenced by COPY" error
|
|
|
|
BEGIN;
|
|
|
|
COPY forcetest (d, e) FROM STDIN WITH (FORMAT csv, FORCE_NULL(b));
|
2015-11-05 03:01:26 +01:00
|
|
|
ERROR: FORCE_NULL column "b" not referenced by COPY
|
2014-03-04 23:31:59 +01:00
|
|
|
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 *);
|
|
|
|
COMMIT;
|
|
|
|
SELECT b, c FROM forcetest WHERE a = 4;
|
|
|
|
b | c
|
|
|
|
---+------
|
|
|
|
| NULL
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- should succeed with effect ("b" remains an empty string)
|
|
|
|
BEGIN;
|
|
|
|
COPY forcetest (a, b, c) FROM STDIN WITH (FORMAT csv, FORCE_NOT_NULL *);
|
|
|
|
COMMIT;
|
|
|
|
SELECT b, c FROM forcetest WHERE a = 5;
|
|
|
|
b | c
|
|
|
|
---+---
|
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- should succeed with effect ("c" remains NULL)
|
|
|
|
BEGIN;
|
|
|
|
COPY forcetest (a, b, c) FROM STDIN WITH (FORMAT csv, FORCE_NULL *);
|
|
|
|
COMMIT;
|
|
|
|
SELECT b, c FROM forcetest WHERE a = 6;
|
|
|
|
b | c
|
|
|
|
---+------
|
|
|
|
b | NULL
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- 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));
|
|
|
|
ERROR: conflicting or redundant options
|
|
|
|
LINE 1: ...c) FROM STDIN WITH (FORMAT csv, FORCE_NOT_NULL *, FORCE_NOT_...
|
|
|
|
^
|
|
|
|
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));
|
|
|
|
ERROR: conflicting or redundant options
|
|
|
|
LINE 1: ... b, c) FROM STDIN WITH (FORMAT csv, FORCE_NULL *, FORCE_NULL...
|
|
|
|
^
|
|
|
|
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
|
2016-11-03 17:00:00 +01:00
|
|
|
Table "public.check_con_tbl"
|
|
|
|
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
|
|
|
|
--------+---------+-----------+----------+---------+---------+--------------+-------------
|
|
|
|
f1 | integer | | | | plain | |
|
2015-02-16 05:26:45 +01:00
|
|
|
Check constraints:
|
|
|
|
"check_con_tbl_check" CHECK (check_con_function(check_con_tbl.*))
|
|
|
|
|
|
|
|
copy check_con_tbl from stdin;
|
|
|
|
NOTICE: input = {"f1":1}
|
|
|
|
NOTICE: input = {"f1":null}
|
|
|
|
copy check_con_tbl from stdin;
|
|
|
|
NOTICE: input = {"f1":0}
|
|
|
|
ERROR: new row for relation "check_con_tbl" violates check constraint "check_con_tbl_check"
|
|
|
|
DETAIL: Failing row contains (0).
|
|
|
|
CONTEXT: COPY check_con_tbl, line 1: "0"
|
|
|
|
select * from check_con_tbl;
|
|
|
|
f1
|
|
|
|
----
|
|
|
|
1
|
|
|
|
|
|
|
|
(2 rows)
|
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
1 4 1
|
|
|
|
2 3 2
|
|
|
|
3 2 3
|
|
|
|
4 1 4
|
|
|
|
COPY rls_t1 (a, b, c) TO stdout;
|
|
|
|
1 4 1
|
|
|
|
2 3 2
|
|
|
|
3 2 3
|
|
|
|
4 1 4
|
|
|
|
-- subset of columns
|
|
|
|
COPY rls_t1 (a) TO stdout;
|
|
|
|
1
|
|
|
|
2
|
|
|
|
3
|
|
|
|
4
|
|
|
|
COPY rls_t1 (a, b) TO stdout;
|
|
|
|
1 4
|
|
|
|
2 3
|
|
|
|
3 2
|
|
|
|
4 1
|
|
|
|
-- column reordering
|
|
|
|
COPY rls_t1 (b, a) TO stdout;
|
|
|
|
4 1
|
|
|
|
3 2
|
|
|
|
2 3
|
|
|
|
1 4
|
|
|
|
SET SESSION AUTHORIZATION regress_rls_copy_user;
|
|
|
|
-- all columns
|
|
|
|
COPY rls_t1 TO stdout;
|
|
|
|
2 3 2
|
|
|
|
4 1 4
|
|
|
|
COPY rls_t1 (a, b, c) TO stdout;
|
|
|
|
2 3 2
|
|
|
|
4 1 4
|
|
|
|
-- subset of columns
|
|
|
|
COPY rls_t1 (a) TO stdout;
|
|
|
|
2
|
|
|
|
4
|
|
|
|
COPY rls_t1 (a, b) TO stdout;
|
|
|
|
2 3
|
|
|
|
4 1
|
|
|
|
-- column reordering
|
|
|
|
COPY rls_t1 (b, a) TO stdout;
|
|
|
|
3 2
|
|
|
|
1 4
|
|
|
|
RESET SESSION AUTHORIZATION;
|
|
|
|
SET SESSION AUTHORIZATION regress_rls_copy_user_colperms;
|
|
|
|
-- attempt all columns (should fail)
|
|
|
|
COPY rls_t1 TO stdout;
|
2017-12-02 15:26:34 +01:00
|
|
|
ERROR: permission denied for table rls_t1
|
2016-10-03 22:22:57 +02:00
|
|
|
COPY rls_t1 (a, b, c) TO stdout;
|
2017-12-02 15:26:34 +01:00
|
|
|
ERROR: permission denied for table rls_t1
|
2016-10-03 22:22:57 +02:00
|
|
|
-- try to copy column with no privileges (should fail)
|
|
|
|
COPY rls_t1 (c) TO stdout;
|
2017-12-02 15:26:34 +01:00
|
|
|
ERROR: permission denied for table rls_t1
|
2016-10-03 22:22:57 +02:00
|
|
|
-- subset of columns (should succeed)
|
|
|
|
COPY rls_t1 (a) TO stdout;
|
|
|
|
2
|
|
|
|
4
|
|
|
|
COPY rls_t1 (a, b) TO stdout;
|
|
|
|
2 3
|
|
|
|
4 1
|
|
|
|
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
|
|
|
|
ERROR: cannot copy to view "instead_of_insert_tbl_view"
|
|
|
|
HINT: To enable copying to a view, provide an INSTEAD OF INSERT trigger.
|
|
|
|
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;
|
|
|
|
SELECT * FROM instead_of_insert_tbl;
|
|
|
|
id | name
|
|
|
|
----+-------
|
|
|
|
1 | test1
|
|
|
|
(1 row)
|
|
|
|
|
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;
|
|
|
|
SELECT * FROM instead_of_insert_tbl;
|
|
|
|
id | name
|
|
|
|
----+-------
|
|
|
|
1 | test1
|
|
|
|
2 | test1
|
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
COMMIT;
|
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
|
|
|
-- tests for SAVE_ERROR_TO option
|
|
|
|
CREATE TABLE check_ign_err (n int, m int[], k int);
|
|
|
|
COPY check_ign_err FROM STDIN WITH (save_error_to error);
|
|
|
|
ERROR: invalid input syntax for type integer: "a"
|
|
|
|
CONTEXT: COPY check_ign_err, line 2, column n: "a"
|
|
|
|
COPY check_ign_err FROM STDIN WITH (save_error_to none);
|
|
|
|
NOTICE: 4 rows were skipped due to data type incompatibility
|
|
|
|
SELECT * FROM check_ign_err;
|
|
|
|
n | m | k
|
|
|
|
---+-----+---
|
|
|
|
1 | {1} | 1
|
|
|
|
5 | {5} | 5
|
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
-- test datatype error that can't be handled as soft: should fail
|
|
|
|
CREATE TABLE hard_err(foo widget);
|
|
|
|
COPY hard_err FROM STDIN WITH (save_error_to none);
|
|
|
|
ERROR: invalid input syntax for type widget: "1"
|
|
|
|
CONTEXT: COPY hard_err, line 1, column foo: "1"
|
|
|
|
-- test missing data: should fail
|
|
|
|
COPY check_ign_err FROM STDIN WITH (save_error_to none);
|
|
|
|
ERROR: missing data for column "k"
|
|
|
|
CONTEXT: COPY check_ign_err, line 1: "1 {1}"
|
|
|
|
-- test extra data: should fail
|
|
|
|
COPY check_ign_err FROM STDIN WITH (save_error_to none);
|
|
|
|
ERROR: extra data after last expected column
|
|
|
|
CONTEXT: COPY check_ign_err, line 1: "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;
|
2012-12-01 14:46:41 +01:00
|
|
|
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;
|
|
|
|
select id, text_value, ts_value from copy_default;
|
|
|
|
id | text_value | ts_value
|
|
|
|
----+------------+--------------------------
|
|
|
|
1 | value | Mon Jul 04 00:00:00 2022
|
|
|
|
2 | D | Tue Jul 05 00:00:00 2022
|
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
truncate copy_default;
|
|
|
|
copy copy_default from stdin with (format csv);
|
|
|
|
select id, text_value, ts_value from copy_default;
|
|
|
|
id | text_value | ts_value
|
|
|
|
----+------------+--------------------------
|
|
|
|
1 | value | Mon Jul 04 00:00:00 2022
|
|
|
|
2 | \D | Tue Jul 05 00:00:00 2022
|
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
truncate copy_default;
|
|
|
|
-- DEFAULT cannot be used in binary mode
|
|
|
|
copy copy_default from stdin with (format binary, default '\D');
|
|
|
|
ERROR: cannot specify DEFAULT in BINARY mode
|
|
|
|
-- DEFAULT cannot be new line nor carriage return
|
|
|
|
copy copy_default from stdin with (default E'\n');
|
|
|
|
ERROR: COPY default representation cannot use newline or carriage return
|
|
|
|
copy copy_default from stdin with (default E'\r');
|
|
|
|
ERROR: COPY default representation cannot use newline or carriage return
|
|
|
|
-- DELIMITER cannot appear in DEFAULT spec
|
|
|
|
copy copy_default from stdin with (delimiter ';', default 'test;test');
|
|
|
|
ERROR: COPY delimiter must not appear in the DEFAULT specification
|
|
|
|
-- CSV quote cannot appear in DEFAULT spec
|
|
|
|
copy copy_default from stdin with (format csv, quote '"', default 'test"test');
|
|
|
|
ERROR: CSV quote character must not appear in the DEFAULT specification
|
|
|
|
-- NULL and DEFAULT spec must be different
|
|
|
|
copy copy_default from stdin with (default '\N');
|
|
|
|
ERROR: NULL specification and DEFAULT specification cannot be the same
|
|
|
|
-- cannot use DEFAULT marker in column that has no DEFAULT value
|
|
|
|
copy copy_default from stdin with (default '\D');
|
2023-07-10 10:46:54 +02:00
|
|
|
ERROR: unexpected default marker in COPY data
|
|
|
|
DETAIL: Column "id" has no default value.
|
2023-03-13 15:01:56 +01:00
|
|
|
CONTEXT: COPY copy_default, line 1: "\D value '2022-07-04'"
|
|
|
|
copy copy_default from stdin with (format csv, default '\D');
|
2023-07-10 10:46:54 +02:00
|
|
|
ERROR: unexpected default marker in COPY data
|
|
|
|
DETAIL: Column "id" has no default value.
|
2023-03-13 15:01:56 +01:00
|
|
|
CONTEXT: COPY copy_default, line 1: "\D,value,2022-07-04"
|
|
|
|
-- The DEFAULT marker must be unquoted and unescaped or it's not recognized
|
|
|
|
copy copy_default from stdin with (default '\D');
|
|
|
|
select id, text_value, ts_value from copy_default;
|
|
|
|
id | text_value | ts_value
|
|
|
|
----+------------+--------------------------
|
|
|
|
1 | test | Mon Jul 04 00:00:00 2022
|
|
|
|
2 | \D | Mon Jul 04 00:00:00 2022
|
|
|
|
3 | "D" | Mon Jul 04 00:00:00 2022
|
|
|
|
(3 rows)
|
|
|
|
|
|
|
|
truncate copy_default;
|
|
|
|
copy copy_default from stdin with (format csv, default '\D');
|
|
|
|
select id, text_value, ts_value from copy_default;
|
|
|
|
id | text_value | ts_value
|
|
|
|
----+------------+--------------------------
|
|
|
|
1 | test | Mon Jul 04 00:00:00 2022
|
|
|
|
2 | \\D | Mon Jul 04 00:00:00 2022
|
|
|
|
3 | \D | Mon Jul 04 00:00:00 2022
|
|
|
|
(3 rows)
|
|
|
|
|
|
|
|
truncate copy_default;
|
|
|
|
-- successful usage of DEFAULT option in COPY
|
|
|
|
copy copy_default from stdin with (default '\D');
|
|
|
|
select id, text_value, ts_value from copy_default;
|
|
|
|
id | text_value | ts_value
|
|
|
|
----+------------+--------------------------
|
|
|
|
1 | value | Mon Jul 04 00:00:00 2022
|
|
|
|
2 | test | Sun Jul 03 00:00:00 2022
|
|
|
|
3 | test | Tue Jul 05 00:00:00 2022
|
|
|
|
(3 rows)
|
|
|
|
|
|
|
|
truncate copy_default;
|
|
|
|
copy copy_default from stdin with (format csv, default '\D');
|
|
|
|
select id, text_value, ts_value from copy_default;
|
|
|
|
id | text_value | ts_value
|
|
|
|
----+------------+--------------------------
|
|
|
|
1 | value | Mon Jul 04 00:00:00 2022
|
|
|
|
2 | test | Sun Jul 03 00:00:00 2022
|
|
|
|
3 | test | Tue Jul 05 00:00:00 2022
|
|
|
|
(3 rows)
|
|
|
|
|
|
|
|
truncate copy_default;
|
|
|
|
-- DEFAULT cannot be used in COPY TO
|
|
|
|
copy (select 1 as test) TO stdout with (default '\D');
|
|
|
|
ERROR: COPY DEFAULT only available using COPY FROM
|