diff options
-rw-r--r-- | src/test/regress/expected/psql.out | 131 | ||||
-rw-r--r-- | src/test/regress/sql/psql.sql | 64 |
2 files changed, 195 insertions, 0 deletions
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out index 5bdae290dce..1047399ef88 100644 --- a/src/test/regress/expected/psql.out +++ b/src/test/regress/expected/psql.out @@ -5433,6 +5433,137 @@ CONTEXT: PL/pgSQL function warn(text) line 2 at RAISE \set SHOW_ALL_RESULTS on DROP FUNCTION warn(TEXT); -- +-- \g with file +-- +\getenv abs_builddir PG_ABS_BUILDDIR +\set g_out_file :abs_builddir '/results/psql-output1' +CREATE TEMPORARY TABLE reload_output( + lineno int NOT NULL GENERATED ALWAYS AS IDENTITY, + line text +); +SELECT 1 AS a \g :g_out_file +COPY reload_output(line) FROM :'g_out_file'; +SELECT 2 AS b\; SELECT 3 AS c\; SELECT 4 AS d \g :g_out_file +COPY reload_output(line) FROM :'g_out_file'; +COPY (SELECT 'foo') TO STDOUT \; COPY (SELECT 'bar') TO STDOUT \g :g_out_file +COPY reload_output(line) FROM :'g_out_file'; +SELECT line FROM reload_output ORDER BY lineno; + line +--------- + a + --- + 1 + (1 row) + + b + --- + 2 + (1 row) + + c + --- + 3 + (1 row) + + d + --- + 4 + (1 row) + + foo + bar +(22 rows) + +TRUNCATE TABLE reload_output; +-- +-- \o with file +-- +\set o_out_file :abs_builddir '/results/psql-output2' +\o :o_out_file +SELECT max(unique1) FROM onek; +SELECT 1 AS a\; SELECT 2 AS b\; SELECT 3 AS c; +-- COPY TO file +-- The data goes to :g_out_file and the status to :o_out_file +\set QUIET false +COPY (SELECT unique1 FROM onek ORDER BY unique1 LIMIT 10) TO :'g_out_file'; +-- DML command status +UPDATE onek SET unique1 = unique1 WHERE false; +\set QUIET true +\o +-- Check the contents of the files generated. +COPY reload_output(line) FROM :'g_out_file'; +SELECT line FROM reload_output ORDER BY lineno; + line +------ + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +(10 rows) + +TRUNCATE TABLE reload_output; +COPY reload_output(line) FROM :'o_out_file'; +SELECT line FROM reload_output ORDER BY lineno; + line +---------- + max + ----- + 999 + (1 row) + + a + --- + 1 + (1 row) + + b + --- + 2 + (1 row) + + c + --- + 3 + (1 row) + + COPY 10 + UPDATE 0 +(22 rows) + +TRUNCATE TABLE reload_output; +-- Multiple COPY TO STDOUT with output file +\o :o_out_file +-- The data goes to :o_out_file with no status generated. +COPY (SELECT 'foo1') TO STDOUT \; COPY (SELECT 'bar1') TO STDOUT; +-- Combination of \o and \g file with multiple COPY queries. +COPY (SELECT 'foo2') TO STDOUT \; COPY (SELECT 'bar2') TO STDOUT \g :g_out_file +\o +-- Check the contents of the files generated. +COPY reload_output(line) FROM :'g_out_file'; +SELECT line FROM reload_output ORDER BY lineno; + line +------ + foo2 + bar2 +(2 rows) + +TRUNCATE TABLE reload_output; +COPY reload_output(line) FROM :'o_out_file'; +SELECT line FROM reload_output ORDER BY lineno; + line +------ + foo1 + bar1 +(2 rows) + +DROP TABLE reload_output; +-- -- AUTOCOMMIT and combined queries -- \set AUTOCOMMIT off diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql index 8732017e51e..cf67a979dfe 100644 --- a/src/test/regress/sql/psql.sql +++ b/src/test/regress/sql/psql.sql @@ -1380,6 +1380,70 @@ SELECT 1 AS one \; SELECT warn('1.5') \; SELECT 2 AS two ; DROP FUNCTION warn(TEXT); -- +-- \g with file +-- +\getenv abs_builddir PG_ABS_BUILDDIR +\set g_out_file :abs_builddir '/results/psql-output1' + +CREATE TEMPORARY TABLE reload_output( + lineno int NOT NULL GENERATED ALWAYS AS IDENTITY, + line text +); + +SELECT 1 AS a \g :g_out_file +COPY reload_output(line) FROM :'g_out_file'; +SELECT 2 AS b\; SELECT 3 AS c\; SELECT 4 AS d \g :g_out_file +COPY reload_output(line) FROM :'g_out_file'; +COPY (SELECT 'foo') TO STDOUT \; COPY (SELECT 'bar') TO STDOUT \g :g_out_file +COPY reload_output(line) FROM :'g_out_file'; + +SELECT line FROM reload_output ORDER BY lineno; +TRUNCATE TABLE reload_output; + +-- +-- \o with file +-- +\set o_out_file :abs_builddir '/results/psql-output2' + +\o :o_out_file +SELECT max(unique1) FROM onek; +SELECT 1 AS a\; SELECT 2 AS b\; SELECT 3 AS c; + +-- COPY TO file +-- The data goes to :g_out_file and the status to :o_out_file +\set QUIET false +COPY (SELECT unique1 FROM onek ORDER BY unique1 LIMIT 10) TO :'g_out_file'; +-- DML command status +UPDATE onek SET unique1 = unique1 WHERE false; +\set QUIET true +\o + +-- Check the contents of the files generated. +COPY reload_output(line) FROM :'g_out_file'; +SELECT line FROM reload_output ORDER BY lineno; +TRUNCATE TABLE reload_output; +COPY reload_output(line) FROM :'o_out_file'; +SELECT line FROM reload_output ORDER BY lineno; +TRUNCATE TABLE reload_output; + +-- Multiple COPY TO STDOUT with output file +\o :o_out_file +-- The data goes to :o_out_file with no status generated. +COPY (SELECT 'foo1') TO STDOUT \; COPY (SELECT 'bar1') TO STDOUT; +-- Combination of \o and \g file with multiple COPY queries. +COPY (SELECT 'foo2') TO STDOUT \; COPY (SELECT 'bar2') TO STDOUT \g :g_out_file +\o + +-- Check the contents of the files generated. +COPY reload_output(line) FROM :'g_out_file'; +SELECT line FROM reload_output ORDER BY lineno; +TRUNCATE TABLE reload_output; +COPY reload_output(line) FROM :'o_out_file'; +SELECT line FROM reload_output ORDER BY lineno; + +DROP TABLE reload_output; + +-- -- AUTOCOMMIT and combined queries -- \set AUTOCOMMIT off |