mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-06 15:24:56 +08:00
Add regression tests for psql's \o and \g on files
This adds coverage for a few scenarios not checked yet in psql, with multiple query combined across files defined by \o, \g or both at the same time. The results are saved in the output files defined, then reloaded back to check what has been written to them. Author: Daniel Verite Discussion: https://postgr.es/m/25c2bb5b-9012-40f8-8088-774cb764046d@manitou-mail.org
This commit is contained in:
parent
66bc9d2d3e
commit
d2a4490401
@ -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
|
||||
|
@ -1379,6 +1379,70 @@ SELECT 1 AS one \; SELECT warn('1.5') \; SELECT 2 AS two ;
|
||||
\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;
|
||||
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
|
||||
--
|
||||
|
Loading…
Reference in New Issue
Block a user