Skip to content

Commit

Permalink
Fix psql of copy binary directory table to.
Browse files Browse the repository at this point in the history
Fix copy binary directory table to, such as:
\copy binary directory table public.test 'aa.bb' to 'bb.aa';

Authored-by: Zhang Wenchao zwcpostgres@gmail.com
  • Loading branch information
wenchaozhang-123 committed Aug 7, 2024
1 parent 228dade commit f722671
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 85 deletions.
2 changes: 1 addition & 1 deletion src/bin/psql/copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ parse_slash_copy(const char *args)

xstrcat(&result->before_tofrom, " ");
xstrcat(&result->before_tofrom, token);
token = strtokx(NULL, whitespace, ".,()", "\"",
token = strtokx(NULL, whitespace, NULL, "\"",
0, false, false, pset.encoding);

if (!token)
Expand Down
15 changes: 13 additions & 2 deletions src/test/regress/input/directory_table.source
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ CREATE DIRECTORY TABLE IF NOT EXISTS dir_table4 TABLESPACE directory_tblspc;
CREATE DIRECTORY TABLE IF NOT EXISTS dir_table2 TABLESPACE directory_tblspc; -- fail
CREATE DIRECTORY TABLE dir_table5 TABLESPACE directory_tblspc;
CREATE DIRECTORY TABLE dir_table6 TABLESPACE pg_default;
CREATE DIRECTORY TABLE "abs.dir_table";

SELECT count(*) FROM pg_directory_table;
SELECT relname, relisshared, relpersistence, relkind FROM pg_class WHERE relname like '%dir_table%' ORDER BY 1;
Expand Down Expand Up @@ -322,6 +323,11 @@ COPY BINARY dir_table2 FROM PROGRAM 'cat @abs_srcdir@/data/nation.csv' 'nation5'
SELECT relative_path, size, tag FROM dir_table2 ORDER BY 1;
SELECT relative_path, content FROM directory_table('dir_table2') ORDER BY 1;

\COPY BINARY dir_table1 FROM '@abs_srcdir@/data/nation.csv' 'nation.txt'; -- OK
COPY BINARY dir_table1 FROM '@abs_srcdir@/data/nation.csv' 'nation2.txt'; -- OK
\COPY BINARY "abs.dir_table" FROM '@abs_srcdir@/data/nation.csv' 'aa.bb'; -- OK
COPY BINARY "abs.dir_table" FROM '@abs_srcdir@/data/nation.csv' 'cc.dd'; -- OK

-- Test copy binary from directory table
\COPY BINARY dir_table1 FROM '@abs_srcdir@/data/nation.csv' 'nation_failed' (format CSV);
\COPY BINARY dir_table1 FROM '@abs_srcdir@/data/nation.csv' 'nation_failed' (freeze off);
Expand Down Expand Up @@ -397,9 +403,13 @@ COPY BINARY DIRECTORY TABLE dir_table1 'nation2' TO stdout; -- OK
\COPY BINARY DIRECTORY TABLE dir_table1 'nation2' TO PROGRAM 'gzip -c -1 > @abs_srcdir@/data/nation2.gz'; -- OK
COPY BINARY DIRECTORY TABLE dir_table1 'nation2' TO PROGRAM 'gzip -c -1 > @abs_srcdir@/data/nation2.gz'; -- OK

\COPY BINARY dir_table1 FROM '@abs_srcdir@/data/nation.csv' 'nation.txt'; -- OK
\COPY BINARY DIRECTORY TABLE "abs.dir_table" 'aa.bb' TO '@abs_srcdir@/data/aa.bb'; -- OK
COPY BINARY DIRECTORY TABLE "abs.dir_table" 'cc.dd' TO '@abs_srcdir@/data/cc.dd'; -- OK
\COPY BINARY DIRECTORY TABLE dir_table1 'nation.txt' TO '@abs_srcdir@/data/nation.txt'; -- OK
COPY BINARY DIRECTORY TABLE dir_table1 'nation.txt' TO '@abs_srcdir@/data/nation2.txt'; -- OK
COPY BINARY DIRECTORY TABLE dir_table1 'nation2.txt' TO '@abs_srcdir@/data/nation2.txt'; -- OK
\COPY BINARY DIRECTORY TABLE public.dir_table1 'nation.txt' TO '@abs_srcdir@/data/nation3.txt'; -- OK
COPY BINARY DIRECTORY TABLE public.dir_table1 'nation2.txt' TO '@abs_srcdir@/data/nation4.txt'; -- OK


SELECT relative_path, size, tag FROM dir_table1 ORDER BY 1;
SELECT relative_path, size, tag FROM dir_table2 ORDER BY 1;
Expand Down Expand Up @@ -621,6 +631,7 @@ DROP DIRECTORY TABLE IF EXISTS dir_table3;
DROP DIRECTORY TABLE IF EXISTS dir_table4;
DROP DIRECTORY TABLE IF EXISTS dir_table5;
DROP DIRECTORY TABLE IF EXISTS dir_table6;
DROP DIRECTORY TABLE IF EXISTS "abs.dir_table";

DROP FUNCTION IF EXISTS triggertest;

Expand Down
91 changes: 55 additions & 36 deletions src/test/regress/output/directory_table.source
Original file line number Diff line number Diff line change
Expand Up @@ -528,28 +528,31 @@ CREATE DIRECTORY TABLE IF NOT EXISTS dir_table2 TABLESPACE directory_tblspc;
NOTICE: relation "dir_table2" already exists, skipping
CREATE DIRECTORY TABLE dir_table5 TABLESPACE directory_tblspc;
CREATE DIRECTORY TABLE dir_table6 TABLESPACE pg_default;
CREATE DIRECTORY TABLE "abs.dir_table";
SELECT count(*) FROM pg_directory_table;
count
-------
6
7
(1 row)

SELECT relname, relisshared, relpersistence, relkind FROM pg_class WHERE relname like '%dir_table%' ORDER BY 1;
relname | relisshared | relpersistence | relkind
-----------------+-------------+----------------+---------
dir_table1 | f | p | d
dir_table1_pkey | f | p | i
dir_table2 | f | p | d
dir_table2_pkey | f | p | i
dir_table3 | f | p | d
dir_table3_pkey | f | p | i
dir_table4 | f | p | d
dir_table4_pkey | f | p | i
dir_table5 | f | p | d
dir_table5_pkey | f | p | i
dir_table6 | f | p | d
dir_table6_pkey | f | p | i
(12 rows)
relname | relisshared | relpersistence | relkind
--------------------+-------------+----------------+---------
abs.dir_table | f | p | d
abs.dir_table_pkey | f | p | i
dir_table1 | f | p | d
dir_table1_pkey | f | p | i
dir_table2 | f | p | d
dir_table2_pkey | f | p | i
dir_table3 | f | p | d
dir_table3_pkey | f | p | i
dir_table4 | f | p | d
dir_table4_pkey | f | p | i
dir_table5 | f | p | d
dir_table5_pkey | f | p | i
dir_table6 | f | p | d
dir_table6_pkey | f | p | i
(14 rows)

\d+ dir_table1;
Directory table "public.dir_table1"
Expand Down Expand Up @@ -628,21 +631,23 @@ NOTICE: directory table "dir_table5" does not exist, skipping
SELECT count(*) FROM pg_directory_table;
count
-------
4
5
(1 row)

SELECT relname, relisshared, relpersistence, relkind FROM pg_class WHERE relname like '%dir_table%' ORDER BY 1;
relname | relisshared | relpersistence | relkind
-----------------+-------------+----------------+---------
dir_table1 | f | p | d
dir_table1_pkey | f | p | i
dir_table2 | f | p | d
dir_table2_pkey | f | p | i
dir_table3 | f | p | d
dir_table3_pkey | f | p | i
dir_table6 | f | p | d
dir_table6_pkey | f | p | i
(8 rows)
relname | relisshared | relpersistence | relkind
--------------------+-------------+----------------+---------
abs.dir_table | f | p | d
abs.dir_table_pkey | f | p | i
dir_table1 | f | p | d
dir_table1_pkey | f | p | i
dir_table2 | f | p | d
dir_table2_pkey | f | p | i
dir_table3 | f | p | d
dir_table3_pkey | f | p | i
dir_table6 | f | p | d
dir_table6_pkey | f | p | i
(10 rows)

\c dirtable_db
SELECT count(*) FROM pg_directory_table;
Expand Down Expand Up @@ -845,6 +850,12 @@ SELECT relative_path, content FROM directory_table('dir_table2') ORDER BY 1;
nation4 | \x307c414c47455249417c307c20686167676c652e206361726566756c6c792066696e616c206465706f736974732064657465637420736c796c7920616761690a317c415247454e54494e417c317c616c20666f7865732070726f6d69736520736c796c79206163636f7264696e6720746f2074686520726567756c6172206163636f756e74732e20626f6c6420726571756573747320616c6f6e0a327c4252415a494c7c317c7920616c6f6e6773696465206f66207468652070656e64696e67206465706f736974732e206361726566756c6c79207370656369616c207061636b61676573206172652061626f7574207468652069726f6e696320666f726765732e20736c796c79207370656369616c200a337c43414e4144417c317c6561732068616e672069726f6e69632c2073696c656e74207061636b616765732e20736c796c7920726567756c6172207061636b616765732061726520667572696f75736c79206f76657220746865207469746865732e20666c756666696c7920626f6c640a347c45475950547c347c792061626f766520746865206361726566756c6c7920756e757375616c207468656f646f6c697465732e2066696e616c206475676f7574732061726520717569636b6c79206163726f73732074686520667572696f75736c7920726567756c617220640a357c455448494f5049417c307c76656e207061636b616765732077616b6520717569636b6c792e20726567750a367c4652414e43457c337c726566756c6c792066696e616c2072657175657374732e20726567756c61722c2069726f6e690a377c4745524d414e597c337c6c20706c6174656c6574732e20726567756c6172206163636f756e747320782d7261793a20756e757375616c2c20726567756c6172206163636f0a387c494e4449417c327c737320657863757365732063616a6f6c6520736c796c79206163726f737320746865207061636b616765732e206465706f73697473207072696e742061726f756e0a397c494e444f4e455349417c327c20736c796c792065787072657373206173796d70746f7465732e20726567756c6172206465706f7369747320686167676c6520736c796c792e206361726566756c6c792069726f6e696320686f636b657920706c617965727320736c65657020626c697468656c792e206361726566756c6c0a31307c4952414e7c347c6566756c6c7920616c6f6e6773696465206f662074686520736c796c792066696e616c20646570656e64656e636965732e200a31317c495241517c347c6e6963206465706f7369747320626f6f73742061746f702074686520717569636b6c792066696e616c2072657175657374733f20717569636b6c7920726567756c610a31327c4a4150414e7c327c6f75736c792e2066696e616c2c20657870726573732067696674732063616a6f6c6520610a31337c4a4f5244414e7c347c6963206465706f736974732061726520626c697468656c792061626f757420746865206361726566756c6c7920726567756c61722070610a31347c4b454e59417c307c2070656e64696e67206578637573657320686167676c6520667572696f75736c79206465706f736974732e2070656e64696e672c20657870726573732070696e746f206265616e732077616b6520666c756666696c79207061737420740a31357c4d4f524f43434f7c307c726e732e20626c697468656c7920626f6c6420636f7572747320616d6f6e672074686520636c6f73656c7920726567756c6172207061636b616765732075736520667572696f75736c7920626f6c6420706c6174656c6574733f0a31367c4d4f5a414d42495155457c307c732e2069726f6e69632c20756e757375616c206173796d70746f7465732077616b6520626c697468656c7920720a31377c504552557c317c706c6174656c6574732e20626c697468656c792070656e64696e6720646570656e64656e636965732075736520666c756666696c79206163726f737320746865206576656e2070696e746f206265616e732e206361726566756c6c792073696c656e74206163636f756e0a31387c4348494e417c327c6320646570656e64656e636965732e20667572696f75736c792065787072657373206e6f746f726e697320736c65657020736c796c7920726567756c6172206163636f756e74732e20696465617320736c6565702e206465706f730a31397c524f4d414e49417c337c756c6172206173796d70746f746573206172652061626f75742074686520667572696f7573206d756c7469706c696572732e206578707265737320646570656e64656e63696573206e61672061626f7665207468652069726f6e6963616c6c792069726f6e6963206163636f756e740a32307c5341554449204152414249417c347c74732e2073696c656e7420726571756573747320686167676c652e20636c6f73656c792065787072657373207061636b6167657320736c656570206163726f73732074686520626c697468656c790a32317c564945544e414d7c327c68656c7920656e746963696e676c792065787072657373206163636f756e74732e206576656e2c2066696e616c200a32327c5255535349417c337c20726571756573747320616761696e73742074686520706c6174656c65747320757365206e65766572206163636f7264696e6720746f2074686520717569636b6c7920726567756c61722070696e740a32337c554e49544544204b494e47444f4d7c337c65616e7320626f6f7374206361726566756c6c79207370656369616c2072657175657374732e206163636f756e7473206172652e206361726566756c6c0a32347c554e49544544205354415445537c317c792066696e616c207061636b616765732e20736c6f7720666f7865732063616a6f6c6520717569636b6c792e20717569636b6c792073696c656e7420706c6174656c657473206272656163682069726f6e6963206163636f756e74732e20756e757375616c2070696e746f2062650a
(4 rows)

\COPY BINARY dir_table1 FROM '@abs_srcdir@/data/nation.csv' 'nation.txt'; -- OK
NOTICE: dir_table1 INSERT AFTER ROW
COPY BINARY dir_table1 FROM '@abs_srcdir@/data/nation.csv' 'nation2.txt'; -- OK
NOTICE: dir_table1 INSERT AFTER ROW
\COPY BINARY "abs.dir_table" FROM '@abs_srcdir@/data/nation.csv' 'aa.bb'; -- OK
COPY BINARY "abs.dir_table" FROM '@abs_srcdir@/data/nation.csv' 'cc.dd'; -- OK
-- Test copy binary from directory table
\COPY BINARY dir_table1 FROM '@abs_srcdir@/data/nation.csv' 'nation_failed' (format CSV);
ERROR: conflicting or redundant options
Expand Down Expand Up @@ -1152,19 +1163,22 @@ COPY BINARY DIRECTORY TABLE dir_table1 'nation2' TO stdout; -- OK
24|UNITED STATES|1|y final packages. slow foxes cajole quickly. quickly silent platelets breach ironic accounts. unusual pinto be
\COPY BINARY DIRECTORY TABLE dir_table1 'nation2' TO PROGRAM 'gzip -c -1 > @abs_srcdir@/data/nation2.gz'; -- OK
COPY BINARY DIRECTORY TABLE dir_table1 'nation2' TO PROGRAM 'gzip -c -1 > @abs_srcdir@/data/nation2.gz'; -- OK
\COPY BINARY dir_table1 FROM '@abs_srcdir@/data/nation.csv' 'nation.txt'; -- OK
NOTICE: dir_table1 INSERT AFTER ROW
\COPY BINARY DIRECTORY TABLE "abs.dir_table" 'aa.bb' TO '@abs_srcdir@/data/aa.bb'; -- OK
COPY BINARY DIRECTORY TABLE "abs.dir_table" 'cc.dd' TO '@abs_srcdir@/data/cc.dd'; -- OK
\COPY BINARY DIRECTORY TABLE dir_table1 'nation.txt' TO '@abs_srcdir@/data/nation.txt'; -- OK
COPY BINARY DIRECTORY TABLE dir_table1 'nation.txt' TO '@abs_srcdir@/data/nation2.txt'; -- OK
COPY BINARY DIRECTORY TABLE dir_table1 'nation2.txt' TO '@abs_srcdir@/data/nation2.txt'; -- OK
\COPY BINARY DIRECTORY TABLE public.dir_table1 'nation.txt' TO '@abs_srcdir@/data/nation3.txt'; -- OK
COPY BINARY DIRECTORY TABLE public.dir_table1 'nation2.txt' TO '@abs_srcdir@/data/nation4.txt'; -- OK
SELECT relative_path, size, tag FROM dir_table1 ORDER BY 1;
relative_path | size | tag
---------------+------+--------
nation1 | 2199 |
nation2 | 2199 |
nation2.txt | 2199 |
nation3 | 2199 | nation
nation4 | 2199 | nation
nation.txt | 2199 |
(5 rows)
(6 rows)

SELECT relative_path, size, tag FROM dir_table2 ORDER BY 1;
relative_path | size | tag
Expand Down Expand Up @@ -1302,10 +1316,11 @@ SELECT relative_path, size, tag FROM dir_table1 ORDER BY 1;
---------------+------+--------
nation1 | 2199 |
nation2 | 2199 |
nation2.txt | 2199 |
nation3 | 2199 | nation
nation4 | 2199 | nation
nation.txt | 2199 |
(5 rows)
(6 rows)

SELECT relative_path, size, tag FROM dir_table2 ORDER BY 1;
relative_path | size | tag
Expand All @@ -1325,10 +1340,11 @@ SELECT relative_path, size, tag FROM dir_table1 ORDER BY 1;
---------------+------+--------
nation1 | 2199 |
nation2 | 2199 |
nation2.txt | 2199 |
nation3 | 2199 | nation
nation4 | 2199 | nation
nation.txt | 2199 |
(5 rows)
(6 rows)

SELECT relative_path, size, tag FROM dir_table2 ORDER BY 1;
relative_path | size | tag
Expand Down Expand Up @@ -1375,10 +1391,11 @@ SELECT relative_path, size, tag FROM dir_table1 ORDER BY 1;
---------------+------+-----------------
nation1 | 2199 | nation_new_tag
nation2 | 2199 | nation2_new_tag
nation2.txt | 2199 | nation_new_tag
nation3 | 2199 | nation_new_tag
nation4 | 2199 | nation_new_tag
nation.txt | 2199 | nation_new_tag
(5 rows)
(6 rows)

SELECT relative_path, size, tag FROM dir_table2 ORDER BY 1;
relative_path | size | tag
Expand Down Expand Up @@ -1467,10 +1484,11 @@ SELECT remove_file('dir_table1', 'nation1'); -- fail
SELECT relative_path, size, tag FROM dir_table1 ORDER BY 1;
relative_path | size | tag
---------------+------+----------------
nation2.txt | 2199 | nation_new_tag
nation3 | 2199 | nation_new_tag
nation4 | 2199 | nation_new_tag
nation.txt | 2199 | nation_new_tag
(3 rows)
(4 rows)

SELECT relative_path, size, tag FROM dir_table2 ORDER BY 1;
relative_path | size | tag
Expand Down Expand Up @@ -1900,6 +1918,7 @@ DROP DIRECTORY TABLE IF EXISTS dir_table4;
DROP DIRECTORY TABLE IF EXISTS dir_table5;
NOTICE: directory table "dir_table5" does not exist, skipping
DROP DIRECTORY TABLE IF EXISTS dir_table6;
DROP DIRECTORY TABLE IF EXISTS "abs.dir_table";
DROP FUNCTION IF EXISTS triggertest;
DROP STORAGE USER MAPPING IF EXISTS FOR CURRENT_USER STORAGE SERVER oss_server1;
DROP STORAGE USER MAPPING IF EXISTS FOR CURRENT_USER STORAGE SERVER oss_server2;
Expand Down
Loading

0 comments on commit f722671

Please sign in to comment.