2 -- Tests for psql features that aren't closely connected to any
3 -- specific server features
10 -- fail: invalid value for special variable
13 -- check handling of built-in boolean variable
14 \echo :ON_ERROR_ROLLBACK
15 \set ON_ERROR_ROLLBACK
16 \echo :ON_ERROR_ROLLBACK
17 \set ON_ERROR_ROLLBACK foo
18 \echo :ON_ERROR_ROLLBACK
19 \set ON_ERROR_ROLLBACK on
20 \echo :ON_ERROR_ROLLBACK
21 \unset ON_ERROR_ROLLBACK
22 \echo :ON_ERROR_ROLLBACK
26 SELECT 1 as one, 2 as two \g
28 SELECT 3 as three, 4 as four \gx
33 select 10 as test01, 20 as test02, 'Hello' as test03 \gset pref01_
35 \echo :pref01_test01 :pref01_test02 :pref01_test03
37 -- should fail: bad variable name
38 select 10 as "bad name"
41 -- multiple backslash commands in one line
42 select 1 as x, 2 as y \gset pref01_ \\ \echo :pref01_x
43 select 3 as x, 4 as y \gset pref01_ \echo :pref01_x \echo :pref01_y
44 select 5 as x, 6 as y \gset pref01_ \\ \g \echo :pref01_x :pref01_y
45 select 7 as x, 8 as y \g \gset pref01_ \echo :pref01_x :pref01_y
47 -- NULL should unset the variable
49 select 1 as var1, NULL as var2, 3 as var3 \gset
50 \echo :var1 :var2 :var3
52 -- \gset requires just one tuple
53 select 10 as test01, 20 as test02 from generate_series(1,3) \gset
54 select 10 as test01, 20 as test02 from generate_series(1,0) \gset
56 -- \gset should work in FETCH_COUNT mode too
59 select 1 as x, 2 as y \gset pref01_ \\ \echo :pref01_x
60 select 3 as x, 4 as y \gset pref01_ \echo :pref01_x \echo :pref01_y
61 select 10 as test01, 20 as test02 from generate_series(1,3) \gset
62 select 10 as test01, 20 as test02 from generate_series(1,0) \gset
68 create temporary table gexec_test(a int, b text, c date, d float);
69 select format('create index on gexec_test(%I)', attname)
71 where attrelid = 'gexec_test'::regclass and attnum > 0
75 -- \gexec should work in FETCH_COUNT mode too
76 -- (though the fetch limit applies to the executed queries not the meta query)
79 select 'select 1 as ones', 'select x.y, x.y*2 as double from generate_series(1,4) as x(y)'
81 select 'drop table gexec_test', NULL
83 select 'drop table gexec_test', 'select ''2000-01-01''::date as party_over'
88 -- show all pset options
91 -- test multi-line headers, wrapping, and newline indicators
92 prepare q as select array_to_string(array_agg(repeat('x',2*n)),E'\n') as "ab
94 c", array_to_string(array_agg(repeat('y',20-2*n)),E'\n') as "a
95 bc" from generate_series(1,10) as n(n) group by n>1 order by n>1;
103 \pset format unaligned
111 \pset format unaligned
119 \pset format unaligned
130 \pset format unaligned
138 \pset format unaligned
146 \pset format unaligned
153 \pset linestyle old-ascii
159 \pset format unaligned
167 \pset format unaligned
175 \pset format unaligned
186 \pset format unaligned
194 \pset format unaligned
202 \pset format unaligned
211 -- test single-line header and data
212 prepare q as select repeat('x',2*n) as "0123456789abcdef", repeat('y',20-2*n) as "0123456789" from generate_series(1,10) as n;
214 \pset linestyle ascii
220 \pset format unaligned
228 \pset format unaligned
236 \pset format unaligned
247 \pset format unaligned
255 \pset format unaligned
263 \pset format unaligned
274 \pset format unaligned
282 \pset format unaligned
290 \pset format unaligned
297 \pset linestyle old-ascii
303 \pset format unaligned
311 \pset format unaligned
319 \pset format unaligned
329 \pset format unaligned
337 \pset format unaligned
345 \pset format unaligned
354 \pset linestyle ascii
356 prepare q as select ' | = | lkjsafi\\/ /oeu rio)(!@&*#)*(!&@*) \ (&' as " | -- | 012345678 9abc def!*@#&!@(*&*~~_+-=\ \", '11' as "0123456789", 11 as int from generate_series(1,10) as n;
358 \pset format asciidoc
385 -- tests for \if ... \endif
395 -- at this point query buffer should still have last valid line
398 -- \if should work okay on part of a query
407 select \if false \\ (bogus \else \\ 42 \endif \\ forty_two;
409 -- test a large nested if using a variety of true-equivalents
416 \echo 'should not print #1-1'
419 \echo 'should not print #1-2'
422 \echo 'should not print #1-3'
425 \echo 'should not print #1-4'
428 -- test a variety of false-equivalents in an if/elif/else structure
430 \echo 'should not print #2-1'
432 \echo 'should not print #2-2'
434 \echo 'should not print #2-3'
436 \echo 'should not print #2-4'
441 -- test simple true-then-else
443 \echo 'first thing true'
445 \echo 'should not print #3-1'
448 -- test simple false-true-else
450 \echo 'should not print #4-1'
452 \echo 'second thing true'
454 \echo 'should not print #5-1'
457 -- invalid boolean expressions are false
458 \if invalid boolean expression
459 \echo 'will not print #6-1'
461 \echo 'will print anyway #6-2'
464 -- test un-matched endif
467 -- test un-matched else
470 -- test un-matched elif
473 -- test double-else error
479 -- test elif out-of-order
485 -- test if-endif matching in a false branch
488 \echo 'should not print #7-1'
490 \echo 'should not print #7-2'
492 \echo 'should not print #7-3'
494 \echo 'should print #7-4'
497 -- show that vars and backticks are not expanded when ignoring extra args
499 \echo :foo :'foo' :"foo"
500 \pset fieldsep | `nosuchcommand` :foo :'foo' :"foo"
502 -- show that vars and backticks are not expanded and commands are ignored
503 -- when in a false if-branch
504 \set try_to_quit '\\q'
507 \echo `nosuchcommand` :foo :'foo' :"foo"
508 \pset fieldsep | `nosuchcommand` :foo :'foo' :"foo"
509 \a \C arg1 \c arg1 arg2 arg3 arg4 \cd arg1 \conninfo
510 \copy arg1 arg2 arg3 arg4 arg5 arg6
511 \copyright \dt arg1 \e arg1 arg2
514 \echo arg1 arg2 arg3 arg4 arg5 \echo arg1 \encoding arg1 \errverbose
515 \g arg1 \gx arg1 \gexec \h \html \i arg1 \ir arg1 \l arg1 \lo arg1 arg2
516 \o arg1 \p \password arg1 \prompt arg1 arg2 \pset arg1 arg2 \q
517 \reset \s arg1 \set arg1 arg2 arg3 arg4 arg5 arg6 arg7 \setenv arg1 arg2
520 \t arg1 \T arg1 \timing arg1 \unset arg1 \w arg1 \watch arg1 \x arg1
521 -- \else here is eaten as part of OT_FILEPIPE argument
522 \w |/no/such/file \else
523 -- \endif here is eaten as part of whole-line argument
526 \echo 'should print #8-1'
531 \set SHOW_CONTEXT never
535 raise exception 'bar';
538 \set SHOW_CONTEXT errors
542 raise exception 'bar';
545 \set SHOW_CONTEXT always
549 raise exception 'bar';