@@ -405,4 +405,32 @@ sub psql_fails_like
405
405
qr / iteration count is specified more than once/ ,
406
406
' \watch, iteration count is specified more than once' );
407
407
408
+ # Test \g output piped into a program.
409
+ # The program is perl -pe '' to simply copy the input to the output.
410
+ my $g_file = " $tempdir /g_file_1.out" ;
411
+ my $perlbin = $^X;
412
+ $perlbin =~ s !\\ ! /! g if $PostgreSQL::Test::Utils::windows_os ;
413
+ my $pipe_cmd = " $perlbin -pe '' >$g_file " ;
414
+
415
+ psql_like($node , " SELECT 'one' \\ g | $pipe_cmd " , qr // , " one command \\ g" );
416
+ my $c1 = slurp_file($g_file );
417
+ like($c1 , qr / one/ );
418
+
419
+ psql_like($node , " SELECT 'two' \\ ; SELECT 'three' \\ g | $pipe_cmd " , qr // , " two commands \\ g" );
420
+ my $c2 = slurp_file($g_file );
421
+ like($c2 , qr / two.*three/ s );
422
+
423
+
424
+ psql_like($node , " \\ set SHOW_ALL_RESULTS 0\n SELECT 'four' \\ ; SELECT 'five' \\ g | $pipe_cmd " , qr // ,
425
+ " two commands \\ g with only last result" );
426
+ my $c3 = slurp_file($g_file );
427
+ like($c3 , qr / five/ );
428
+ unlike($c3 , qr / four/ );
429
+
430
+ psql_like($node , " copy (values ('foo'),('bar')) to stdout \\ g | $pipe_cmd " ,
431
+ qr // ,
432
+ " copy output passed to \\ g pipe" );
433
+ my $c4 = slurp_file($g_file );
434
+ like($c4 , qr / foo.*bar/ s );
435
+
408
436
done_testing();
0 commit comments