Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d2a4490

Browse files
committed
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
1 parent 66bc9d2 commit d2a4490

File tree

2 files changed

+195
-0
lines changed

2 files changed

+195
-0
lines changed

src/test/regress/expected/psql.out

+131
Original file line numberDiff line numberDiff line change
@@ -5433,6 +5433,137 @@ CONTEXT: PL/pgSQL function warn(text) line 2 at RAISE
54335433
\set SHOW_ALL_RESULTS on
54345434
DROP FUNCTION warn(TEXT);
54355435
--
5436+
-- \g with file
5437+
--
5438+
\getenv abs_builddir PG_ABS_BUILDDIR
5439+
\set g_out_file :abs_builddir '/results/psql-output1'
5440+
CREATE TEMPORARY TABLE reload_output(
5441+
lineno int NOT NULL GENERATED ALWAYS AS IDENTITY,
5442+
line text
5443+
);
5444+
SELECT 1 AS a \g :g_out_file
5445+
COPY reload_output(line) FROM :'g_out_file';
5446+
SELECT 2 AS b\; SELECT 3 AS c\; SELECT 4 AS d \g :g_out_file
5447+
COPY reload_output(line) FROM :'g_out_file';
5448+
COPY (SELECT 'foo') TO STDOUT \; COPY (SELECT 'bar') TO STDOUT \g :g_out_file
5449+
COPY reload_output(line) FROM :'g_out_file';
5450+
SELECT line FROM reload_output ORDER BY lineno;
5451+
line
5452+
---------
5453+
a
5454+
---
5455+
1
5456+
(1 row)
5457+
5458+
b
5459+
---
5460+
2
5461+
(1 row)
5462+
5463+
c
5464+
---
5465+
3
5466+
(1 row)
5467+
5468+
d
5469+
---
5470+
4
5471+
(1 row)
5472+
5473+
foo
5474+
bar
5475+
(22 rows)
5476+
5477+
TRUNCATE TABLE reload_output;
5478+
--
5479+
-- \o with file
5480+
--
5481+
\set o_out_file :abs_builddir '/results/psql-output2'
5482+
\o :o_out_file
5483+
SELECT max(unique1) FROM onek;
5484+
SELECT 1 AS a\; SELECT 2 AS b\; SELECT 3 AS c;
5485+
-- COPY TO file
5486+
-- The data goes to :g_out_file and the status to :o_out_file
5487+
\set QUIET false
5488+
COPY (SELECT unique1 FROM onek ORDER BY unique1 LIMIT 10) TO :'g_out_file';
5489+
-- DML command status
5490+
UPDATE onek SET unique1 = unique1 WHERE false;
5491+
\set QUIET true
5492+
\o
5493+
-- Check the contents of the files generated.
5494+
COPY reload_output(line) FROM :'g_out_file';
5495+
SELECT line FROM reload_output ORDER BY lineno;
5496+
line
5497+
------
5498+
0
5499+
1
5500+
2
5501+
3
5502+
4
5503+
5
5504+
6
5505+
7
5506+
8
5507+
9
5508+
(10 rows)
5509+
5510+
TRUNCATE TABLE reload_output;
5511+
COPY reload_output(line) FROM :'o_out_file';
5512+
SELECT line FROM reload_output ORDER BY lineno;
5513+
line
5514+
----------
5515+
max
5516+
-----
5517+
999
5518+
(1 row)
5519+
5520+
a
5521+
---
5522+
1
5523+
(1 row)
5524+
5525+
b
5526+
---
5527+
2
5528+
(1 row)
5529+
5530+
c
5531+
---
5532+
3
5533+
(1 row)
5534+
5535+
COPY 10
5536+
UPDATE 0
5537+
(22 rows)
5538+
5539+
TRUNCATE TABLE reload_output;
5540+
-- Multiple COPY TO STDOUT with output file
5541+
\o :o_out_file
5542+
-- The data goes to :o_out_file with no status generated.
5543+
COPY (SELECT 'foo1') TO STDOUT \; COPY (SELECT 'bar1') TO STDOUT;
5544+
-- Combination of \o and \g file with multiple COPY queries.
5545+
COPY (SELECT 'foo2') TO STDOUT \; COPY (SELECT 'bar2') TO STDOUT \g :g_out_file
5546+
\o
5547+
-- Check the contents of the files generated.
5548+
COPY reload_output(line) FROM :'g_out_file';
5549+
SELECT line FROM reload_output ORDER BY lineno;
5550+
line
5551+
------
5552+
foo2
5553+
bar2
5554+
(2 rows)
5555+
5556+
TRUNCATE TABLE reload_output;
5557+
COPY reload_output(line) FROM :'o_out_file';
5558+
SELECT line FROM reload_output ORDER BY lineno;
5559+
line
5560+
------
5561+
foo1
5562+
bar1
5563+
(2 rows)
5564+
5565+
DROP TABLE reload_output;
5566+
--
54365567
-- AUTOCOMMIT and combined queries
54375568
--
54385569
\set AUTOCOMMIT off

src/test/regress/sql/psql.sql

+64
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,70 @@ SELECT 1 AS one \; SELECT warn('1.5') \; SELECT 2 AS two ;
13791379
\set SHOW_ALL_RESULTS on
13801380
DROP FUNCTION warn(TEXT);
13811381

1382+
--
1383+
-- \g with file
1384+
--
1385+
\getenv abs_builddir PG_ABS_BUILDDIR
1386+
\set g_out_file :abs_builddir '/results/psql-output1'
1387+
1388+
CREATE TEMPORARY TABLE reload_output(
1389+
lineno int NOT NULL GENERATED ALWAYS AS IDENTITY,
1390+
line text
1391+
);
1392+
1393+
SELECT 1 AS a \g :g_out_file
1394+
COPY reload_output(line) FROM :'g_out_file';
1395+
SELECT 2 AS b\; SELECT 3 AS c\; SELECT 4 AS d \g :g_out_file
1396+
COPY reload_output(line) FROM :'g_out_file';
1397+
COPY (SELECT 'foo') TO STDOUT \; COPY (SELECT 'bar') TO STDOUT \g :g_out_file
1398+
COPY reload_output(line) FROM :'g_out_file';
1399+
1400+
SELECT line FROM reload_output ORDER BY lineno;
1401+
TRUNCATE TABLE reload_output;
1402+
1403+
--
1404+
-- \o with file
1405+
--
1406+
\set o_out_file :abs_builddir '/results/psql-output2'
1407+
1408+
\o :o_out_file
1409+
SELECT max(unique1) FROM onek;
1410+
SELECT 1 AS a\; SELECT 2 AS b\; SELECT 3 AS c;
1411+
1412+
-- COPY TO file
1413+
-- The data goes to :g_out_file and the status to :o_out_file
1414+
\set QUIET false
1415+
COPY (SELECT unique1 FROM onek ORDER BY unique1 LIMIT 10) TO :'g_out_file';
1416+
-- DML command status
1417+
UPDATE onek SET unique1 = unique1 WHERE false;
1418+
\set QUIET true
1419+
\o
1420+
1421+
-- Check the contents of the files generated.
1422+
COPY reload_output(line) FROM :'g_out_file';
1423+
SELECT line FROM reload_output ORDER BY lineno;
1424+
TRUNCATE TABLE reload_output;
1425+
COPY reload_output(line) FROM :'o_out_file';
1426+
SELECT line FROM reload_output ORDER BY lineno;
1427+
TRUNCATE TABLE reload_output;
1428+
1429+
-- Multiple COPY TO STDOUT with output file
1430+
\o :o_out_file
1431+
-- The data goes to :o_out_file with no status generated.
1432+
COPY (SELECT 'foo1') TO STDOUT \; COPY (SELECT 'bar1') TO STDOUT;
1433+
-- Combination of \o and \g file with multiple COPY queries.
1434+
COPY (SELECT 'foo2') TO STDOUT \; COPY (SELECT 'bar2') TO STDOUT \g :g_out_file
1435+
\o
1436+
1437+
-- Check the contents of the files generated.
1438+
COPY reload_output(line) FROM :'g_out_file';
1439+
SELECT line FROM reload_output ORDER BY lineno;
1440+
TRUNCATE TABLE reload_output;
1441+
COPY reload_output(line) FROM :'o_out_file';
1442+
SELECT line FROM reload_output ORDER BY lineno;
1443+
1444+
DROP TABLE reload_output;
1445+
13821446
--
13831447
-- AUTOCOMMIT and combined queries
13841448
--

0 commit comments

Comments
 (0)