]> granicus.if.org Git - postgresql/blob - src/test/regress/sql/psql.sql
Fix initialization of fake LSN for unlogged relations
[postgresql] / src / test / regress / sql / psql.sql
1 --
2 -- Tests for psql features that aren't closely connected to any
3 -- specific server features
4 --
5
6 -- \set
7
8 -- fail: invalid name
9 \set invalid/name foo
10 -- fail: invalid value for special variable
11 \set AUTOCOMMIT foo
12 \set FETCH_COUNT foo
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
23
24 -- \g and \gx
25
26 SELECT 1 as one, 2 as two \g
27 \gx
28 SELECT 3 as three, 4 as four \gx
29 \g
30
31 -- \gx should work in FETCH_COUNT mode too
32 \set FETCH_COUNT 1
33
34 SELECT 1 as one, 2 as two \g
35 \gx
36 SELECT 3 as three, 4 as four \gx
37 \g
38
39 \unset FETCH_COUNT
40
41 -- \gset
42
43 select 10 as test01, 20 as test02, 'Hello' as test03 \gset pref01_
44
45 \echo :pref01_test01 :pref01_test02 :pref01_test03
46
47 -- should fail: bad variable name
48 select 10 as "bad name"
49 \gset
50
51 -- multiple backslash commands in one line
52 select 1 as x, 2 as y \gset pref01_ \\ \echo :pref01_x
53 select 3 as x, 4 as y \gset pref01_ \echo :pref01_x \echo :pref01_y
54 select 5 as x, 6 as y \gset pref01_ \\ \g \echo :pref01_x :pref01_y
55 select 7 as x, 8 as y \g \gset pref01_ \echo :pref01_x :pref01_y
56
57 -- NULL should unset the variable
58 \set var2 xyz
59 select 1 as var1, NULL as var2, 3 as var3 \gset
60 \echo :var1 :var2 :var3
61
62 -- \gset requires just one tuple
63 select 10 as test01, 20 as test02 from generate_series(1,3) \gset
64 select 10 as test01, 20 as test02 from generate_series(1,0) \gset
65
66 -- \gset should work in FETCH_COUNT mode too
67 \set FETCH_COUNT 1
68
69 select 1 as x, 2 as y \gset pref01_ \\ \echo :pref01_x
70 select 3 as x, 4 as y \gset pref01_ \echo :pref01_x \echo :pref01_y
71 select 10 as test01, 20 as test02 from generate_series(1,3) \gset
72 select 10 as test01, 20 as test02 from generate_series(1,0) \gset
73
74 \unset FETCH_COUNT
75
76 -- \gdesc
77
78 SELECT
79     NULL AS zero,
80     1 AS one,
81     2.0 AS two,
82     'three' AS three,
83     $1 AS four,
84     sin($2) as five,
85     'foo'::varchar(4) as six,
86     CURRENT_DATE AS now
87 \gdesc
88
89 -- should work with tuple-returning utilities, such as EXECUTE
90 PREPARE test AS SELECT 1 AS first, 2 AS second;
91 EXECUTE test \gdesc
92 EXPLAIN EXECUTE test \gdesc
93
94 -- should fail cleanly - syntax error
95 SELECT 1 + \gdesc
96
97 -- check behavior with empty results
98 SELECT \gdesc
99 CREATE TABLE bububu(a int) \gdesc
100
101 -- subject command should not have executed
102 TABLE bububu;  -- fail
103
104 -- query buffer should remain unchanged
105 SELECT 1 AS x, 'Hello', 2 AS y, true AS "dirty\name"
106 \gdesc
107 \g
108
109 -- all on one line
110 SELECT 3 AS x, 'Hello', 4 AS y, true AS "dirty\name" \gdesc \g
111
112 -- \gexec
113
114 create temporary table gexec_test(a int, b text, c date, d float);
115 select format('create index on gexec_test(%I)', attname)
116 from pg_attribute
117 where attrelid = 'gexec_test'::regclass and attnum > 0
118 order by attnum
119 \gexec
120
121 -- \gexec should work in FETCH_COUNT mode too
122 -- (though the fetch limit applies to the executed queries not the meta query)
123 \set FETCH_COUNT 1
124
125 select 'select 1 as ones', 'select x.y, x.y*2 as double from generate_series(1,4) as x(y)'
126 union all
127 select 'drop table gexec_test', NULL
128 union all
129 select 'drop table gexec_test', 'select ''2000-01-01''::date as party_over'
130 \gexec
131
132 \unset FETCH_COUNT
133
134 -- show all pset options
135 \pset
136
137 -- test multi-line headers, wrapping, and newline indicators
138 -- in aligned, unaligned, and wrapped formats
139 prepare q as select array_to_string(array_agg(repeat('x',2*n)),E'\n') as "ab
140
141 c", array_to_string(array_agg(repeat('y',20-2*n)),E'\n') as "a
142 bc" from generate_series(1,10) as n(n) group by n>1 order by n>1;
143
144 \pset linestyle ascii
145
146 \pset expanded off
147 \pset columns 40
148
149 \pset border 0
150 \pset format unaligned
151 execute q;
152 \pset format aligned
153 execute q;
154 \pset format wrapped
155 execute q;
156
157 \pset border 1
158 \pset format unaligned
159 execute q;
160 \pset format aligned
161 execute q;
162 \pset format wrapped
163 execute q;
164
165 \pset border 2
166 \pset format unaligned
167 execute q;
168 \pset format aligned
169 execute q;
170 \pset format wrapped
171 execute q;
172
173 \pset expanded on
174 \pset columns 20
175
176 \pset border 0
177 \pset format unaligned
178 execute q;
179 \pset format aligned
180 execute q;
181 \pset format wrapped
182 execute q;
183
184 \pset border 1
185 \pset format unaligned
186 execute q;
187 \pset format aligned
188 execute q;
189 \pset format wrapped
190 execute q;
191
192 \pset border 2
193 \pset format unaligned
194 execute q;
195 \pset format aligned
196 execute q;
197 \pset format wrapped
198 execute q;
199
200 \pset linestyle old-ascii
201
202 \pset expanded off
203 \pset columns 40
204
205 \pset border 0
206 \pset format unaligned
207 execute q;
208 \pset format aligned
209 execute q;
210 \pset format wrapped
211 execute q;
212
213 \pset border 1
214 \pset format unaligned
215 execute q;
216 \pset format aligned
217 execute q;
218 \pset format wrapped
219 execute q;
220
221 \pset border 2
222 \pset format unaligned
223 execute q;
224 \pset format aligned
225 execute q;
226 \pset format wrapped
227 execute q;
228
229 \pset expanded on
230 \pset columns 20
231
232 \pset border 0
233 \pset format unaligned
234 execute q;
235 \pset format aligned
236 execute q;
237 \pset format wrapped
238 execute q;
239
240 \pset border 1
241 \pset format unaligned
242 execute q;
243 \pset format aligned
244 execute q;
245 \pset format wrapped
246 execute q;
247
248 \pset border 2
249 \pset format unaligned
250 execute q;
251 \pset format aligned
252 execute q;
253 \pset format wrapped
254 execute q;
255
256 deallocate q;
257
258 -- test single-line header and data
259 prepare q as select repeat('x',2*n) as "0123456789abcdef", repeat('y',20-2*n) as "0123456789" from generate_series(1,10) as n;
260
261 \pset linestyle ascii
262
263 \pset expanded off
264 \pset columns 40
265
266 \pset border 0
267 \pset format unaligned
268 execute q;
269 \pset format aligned
270 execute q;
271 \pset format wrapped
272 execute q;
273
274 \pset border 1
275 \pset format unaligned
276 execute q;
277 \pset format aligned
278 execute q;
279 \pset format wrapped
280 execute q;
281
282 \pset border 2
283 \pset format unaligned
284 execute q;
285 \pset format aligned
286 execute q;
287 \pset format wrapped
288 execute q;
289
290 \pset expanded on
291 \pset columns 30
292
293 \pset border 0
294 \pset format unaligned
295 execute q;
296 \pset format aligned
297 execute q;
298 \pset format wrapped
299 execute q;
300
301 \pset border 1
302 \pset format unaligned
303 execute q;
304 \pset format aligned
305 execute q;
306 \pset format wrapped
307 execute q;
308
309 \pset border 2
310 \pset format unaligned
311 execute q;
312 \pset format aligned
313 execute q;
314 \pset format wrapped
315 execute q;
316
317 \pset expanded on
318 \pset columns 20
319
320 \pset border 0
321 \pset format unaligned
322 execute q;
323 \pset format aligned
324 execute q;
325 \pset format wrapped
326 execute q;
327
328 \pset border 1
329 \pset format unaligned
330 execute q;
331 \pset format aligned
332 execute q;
333 \pset format wrapped
334 execute q;
335
336 \pset border 2
337 \pset format unaligned
338 execute q;
339 \pset format aligned
340 execute q;
341 \pset format wrapped
342 execute q;
343
344 \pset linestyle old-ascii
345
346 \pset expanded off
347 \pset columns 40
348
349 \pset border 0
350 \pset format unaligned
351 execute q;
352 \pset format aligned
353 execute q;
354 \pset format wrapped
355 execute q;
356
357 \pset border 1
358 \pset format unaligned
359 execute q;
360 \pset format aligned
361 execute q;
362 \pset format wrapped
363 execute q;
364
365 \pset border 2
366 \pset format unaligned
367 execute q;
368 \pset format aligned
369 execute q;
370 \pset format wrapped
371 execute q;
372
373 \pset expanded on
374
375 \pset border 0
376 \pset format unaligned
377 execute q;
378 \pset format aligned
379 execute q;
380 \pset format wrapped
381 execute q;
382
383 \pset border 1
384 \pset format unaligned
385 execute q;
386 \pset format aligned
387 execute q;
388 \pset format wrapped
389 execute q;
390
391 \pset border 2
392 \pset format unaligned
393 execute q;
394 \pset format aligned
395 execute q;
396 \pset format wrapped
397 execute q;
398
399 deallocate q;
400
401 \pset linestyle ascii
402 \pset border 1
403
404 -- support table for output-format tests (useful to create a footer)
405
406 create table psql_serial_tab (id serial);
407
408 -- test header/footer/tuples_only behavior in aligned/unaligned/wrapped cases
409
410 \pset format aligned
411
412 \pset expanded off
413 \d psql_serial_tab_id_seq
414 \pset tuples_only true
415 \df exp
416 \pset tuples_only false
417 \pset expanded on
418 \d psql_serial_tab_id_seq
419 \pset tuples_only true
420 \df exp
421 \pset tuples_only false
422 -- empty table is a special case for this format
423 select 1 where false;
424
425 \pset format unaligned
426
427 \pset expanded off
428 \d psql_serial_tab_id_seq
429 \pset tuples_only true
430 \df exp
431 \pset tuples_only false
432 \pset expanded on
433 \d psql_serial_tab_id_seq
434 \pset tuples_only true
435 \df exp
436 \pset tuples_only false
437
438 \pset format wrapped
439
440 \pset expanded off
441 \d psql_serial_tab_id_seq
442 \pset tuples_only true
443 \df exp
444 \pset tuples_only false
445 \pset expanded on
446 \d psql_serial_tab_id_seq
447 \pset tuples_only true
448 \df exp
449 \pset tuples_only false
450
451 -- check conditional tableam display
452
453 -- Create a heap2 table am handler with heapam handler
454 CREATE ACCESS METHOD heap_psql TYPE TABLE HANDLER heap_tableam_handler;
455 CREATE TABLE tbl_heap_psql(f1 int, f2 char(100)) using heap_psql;
456 CREATE TABLE tbl_heap(f1 int, f2 char(100)) using heap;
457 \d+ tbl_heap_psql
458 \d+ tbl_heap
459 \set HIDE_TABLEAM off
460 \d+ tbl_heap_psql
461 \d+ tbl_heap
462 \set HIDE_TABLEAM on
463 DROP TABLE tbl_heap, tbl_heap_psql;
464 DROP ACCESS METHOD heap_psql;
465
466 -- test numericlocale (as best we can without control of psql's locale)
467
468 \pset format aligned
469 \pset expanded off
470 \pset numericlocale true
471
472 select n, -n as m, n * 111 as x, '1e90'::float8 as f
473 from generate_series(0,3) n;
474
475 \pset numericlocale false
476
477 -- test asciidoc output format
478
479 \pset format asciidoc
480
481 \pset border 1
482 \pset expanded off
483 \d psql_serial_tab_id_seq
484 \pset tuples_only true
485 \df exp
486 \pset tuples_only false
487 \pset expanded on
488 \d psql_serial_tab_id_seq
489 \pset tuples_only true
490 \df exp
491 \pset tuples_only false
492
493 prepare q as
494   select 'some|text' as "a|title", '        ' as "empty ", n as int
495   from generate_series(1,2) as n;
496
497 \pset expanded off
498 \pset border 0
499 execute q;
500
501 \pset border 1
502 execute q;
503
504 \pset border 2
505 execute q;
506
507 \pset expanded on
508 \pset border 0
509 execute q;
510
511 \pset border 1
512 execute q;
513
514 \pset border 2
515 execute q;
516
517 deallocate q;
518
519 -- test csv output format
520
521 \pset format csv
522
523 \pset border 1
524 \pset expanded off
525 \d psql_serial_tab_id_seq
526 \pset tuples_only true
527 \df exp
528 \pset tuples_only false
529 \pset expanded on
530 \d psql_serial_tab_id_seq
531 \pset tuples_only true
532 \df exp
533 \pset tuples_only false
534
535 prepare q as
536   select 'some"text' as "a""title", E'  <foo>\n<bar>' as "junk",
537          '   ' as "empty", n as int
538   from generate_series(1,2) as n;
539
540 \pset expanded off
541 execute q;
542
543 \pset expanded on
544 execute q;
545
546 deallocate q;
547
548 -- special cases
549 \pset expanded off
550 select 'comma,comma' as comma, 'semi;semi' as semi;
551 \pset csv_fieldsep ';'
552 select 'comma,comma' as comma, 'semi;semi' as semi;
553 select '\.' as data;
554 \pset csv_fieldsep '.'
555 select '\' as d1, '' as d2;
556
557 -- illegal csv separators
558 \pset csv_fieldsep ''
559 \pset csv_fieldsep '\0'
560 \pset csv_fieldsep '\n'
561 \pset csv_fieldsep '\r'
562 \pset csv_fieldsep '"'
563 \pset csv_fieldsep ',,'
564
565 \pset csv_fieldsep ','
566
567 -- test html output format
568
569 \pset format html
570
571 \pset border 1
572 \pset expanded off
573 \d psql_serial_tab_id_seq
574 \pset tuples_only true
575 \df exp
576 \pset tuples_only false
577 \pset expanded on
578 \d psql_serial_tab_id_seq
579 \pset tuples_only true
580 \df exp
581 \pset tuples_only false
582
583 prepare q as
584   select 'some"text' as "a&title", E'  <foo>\n<bar>' as "junk",
585          '   ' as "empty", n as int
586   from generate_series(1,2) as n;
587
588 \pset expanded off
589 \pset border 0
590 execute q;
591
592 \pset border 1
593 execute q;
594
595 \pset tableattr foobar
596 execute q;
597 \pset tableattr
598
599 \pset expanded on
600 \pset border 0
601 execute q;
602
603 \pset border 1
604 execute q;
605
606 \pset tableattr foobar
607 execute q;
608 \pset tableattr
609
610 deallocate q;
611
612 -- test latex output format
613
614 \pset format latex
615
616 \pset border 1
617 \pset expanded off
618 \d psql_serial_tab_id_seq
619 \pset tuples_only true
620 \df exp
621 \pset tuples_only false
622 \pset expanded on
623 \d psql_serial_tab_id_seq
624 \pset tuples_only true
625 \df exp
626 \pset tuples_only false
627
628 prepare q as
629   select 'some\more_text' as "a$title", E'  #<foo>%&^~|\n{bar}' as "junk",
630          '   ' as "empty", n as int
631   from generate_series(1,2) as n;
632
633 \pset expanded off
634 \pset border 0
635 execute q;
636
637 \pset border 1
638 execute q;
639
640 \pset border 2
641 execute q;
642
643 \pset border 3
644 execute q;
645
646 \pset expanded on
647 \pset border 0
648 execute q;
649
650 \pset border 1
651 execute q;
652
653 \pset border 2
654 execute q;
655
656 \pset border 3
657 execute q;
658
659 deallocate q;
660
661 -- test latex-longtable output format
662
663 \pset format latex-longtable
664
665 \pset border 1
666 \pset expanded off
667 \d psql_serial_tab_id_seq
668 \pset tuples_only true
669 \df exp
670 \pset tuples_only false
671 \pset expanded on
672 \d psql_serial_tab_id_seq
673 \pset tuples_only true
674 \df exp
675 \pset tuples_only false
676
677 prepare q as
678   select 'some\more_text' as "a$title", E'  #<foo>%&^~|\n{bar}' as "junk",
679          '   ' as "empty", n as int
680   from generate_series(1,2) as n;
681
682 \pset expanded off
683 \pset border 0
684 execute q;
685
686 \pset border 1
687 execute q;
688
689 \pset border 2
690 execute q;
691
692 \pset border 3
693 execute q;
694
695 \pset tableattr lr
696 execute q;
697 \pset tableattr
698
699 \pset expanded on
700 \pset border 0
701 execute q;
702
703 \pset border 1
704 execute q;
705
706 \pset border 2
707 execute q;
708
709 \pset border 3
710 execute q;
711
712 \pset tableattr lr
713 execute q;
714 \pset tableattr
715
716 deallocate q;
717
718 -- test troff-ms output format
719
720 \pset format troff-ms
721
722 \pset border 1
723 \pset expanded off
724 \d psql_serial_tab_id_seq
725 \pset tuples_only true
726 \df exp
727 \pset tuples_only false
728 \pset expanded on
729 \d psql_serial_tab_id_seq
730 \pset tuples_only true
731 \df exp
732 \pset tuples_only false
733
734 prepare q as
735   select 'some\text' as "a\title", E'  <foo>\n<bar>' as "junk",
736          '   ' as "empty", n as int
737   from generate_series(1,2) as n;
738
739 \pset expanded off
740 \pset border 0
741 execute q;
742
743 \pset border 1
744 execute q;
745
746 \pset border 2
747 execute q;
748
749 \pset expanded on
750 \pset border 0
751 execute q;
752
753 \pset border 1
754 execute q;
755
756 \pset border 2
757 execute q;
758
759 deallocate q;
760
761 -- check ambiguous format requests
762
763 \pset format a
764 \pset format l
765
766 -- clean up after output format tests
767
768 drop table psql_serial_tab;
769
770 \pset format aligned
771 \pset expanded off
772 \pset border 1
773
774 -- \echo and allied features
775
776 \echo this is a test
777 \echo -n without newline
778 \echo with -n newline
779 \echo '-n' with newline
780
781 \set foo bar
782 \echo foo = :foo
783
784 \qecho this is a test
785 \qecho foo = :foo
786
787 \warn this is a test
788 \warn foo = :foo
789
790 -- tests for \if ... \endif
791
792 \if true
793   select 'okay';
794   select 'still okay';
795 \else
796   not okay;
797   still not okay
798 \endif
799
800 -- at this point query buffer should still have last valid line
801 \g
802
803 -- \if should work okay on part of a query
804 select
805   \if true
806     42
807   \else
808     (bogus
809   \endif
810   forty_two;
811
812 select \if false \\ (bogus \else \\ 42 \endif \\ forty_two;
813
814 -- test a large nested if using a variety of true-equivalents
815 \if true
816         \if 1
817                 \if yes
818                         \if on
819                                 \echo 'all true'
820                         \else
821                                 \echo 'should not print #1-1'
822                         \endif
823                 \else
824                         \echo 'should not print #1-2'
825                 \endif
826         \else
827                 \echo 'should not print #1-3'
828         \endif
829 \else
830         \echo 'should not print #1-4'
831 \endif
832
833 -- test a variety of false-equivalents in an if/elif/else structure
834 \if false
835         \echo 'should not print #2-1'
836 \elif 0
837         \echo 'should not print #2-2'
838 \elif no
839         \echo 'should not print #2-3'
840 \elif off
841         \echo 'should not print #2-4'
842 \else
843         \echo 'all false'
844 \endif
845
846 -- test true-false elif after initial true branch
847 \if true
848         \echo 'should print #2-5'
849 \elif true
850         \echo 'should not print #2-6'
851 \elif false
852         \echo 'should not print #2-7'
853 \else
854         \echo 'should not print #2-8'
855 \endif
856
857 -- test simple true-then-else
858 \if true
859         \echo 'first thing true'
860 \else
861         \echo 'should not print #3-1'
862 \endif
863
864 -- test simple false-true-else
865 \if false
866         \echo 'should not print #4-1'
867 \elif true
868         \echo 'second thing true'
869 \else
870         \echo 'should not print #5-1'
871 \endif
872
873 -- invalid boolean expressions are false
874 \if invalid boolean expression
875         \echo 'will not print #6-1'
876 \else
877         \echo 'will print anyway #6-2'
878 \endif
879
880 -- test un-matched endif
881 \endif
882
883 -- test un-matched else
884 \else
885
886 -- test un-matched elif
887 \elif
888
889 -- test double-else error
890 \if true
891 \else
892 \else
893 \endif
894
895 -- test elif out-of-order
896 \if false
897 \else
898 \elif
899 \endif
900
901 -- test if-endif matching in a false branch
902 \if false
903     \if false
904         \echo 'should not print #7-1'
905     \else
906         \echo 'should not print #7-2'
907     \endif
908     \echo 'should not print #7-3'
909 \else
910     \echo 'should print #7-4'
911 \endif
912
913 -- show that vars and backticks are not expanded when ignoring extra args
914 \set foo bar
915 \echo :foo :'foo' :"foo"
916 \pset fieldsep | `nosuchcommand` :foo :'foo' :"foo"
917
918 -- show that vars and backticks are not expanded and commands are ignored
919 -- when in a false if-branch
920 \set try_to_quit '\\q'
921 \if false
922         :try_to_quit
923         \echo `nosuchcommand` :foo :'foo' :"foo"
924         \pset fieldsep | `nosuchcommand` :foo :'foo' :"foo"
925         \a
926         \C arg1
927         \c arg1 arg2 arg3 arg4
928         \cd arg1
929         \conninfo
930         \copy arg1 arg2 arg3 arg4 arg5 arg6
931         \copyright
932         SELECT 1 as one, 2, 3 \crosstabview
933         \dt arg1
934         \e arg1 arg2
935         \ef whole_line
936         \ev whole_line
937         \echo arg1 arg2 arg3 arg4 arg5
938         \echo arg1
939         \encoding arg1
940         \errverbose
941         \f arg1
942         \g arg1
943         \gx arg1
944         \gexec
945         SELECT 1 AS one \gset
946         \h
947         \?
948         \html
949         \i arg1
950         \ir arg1
951         \l arg1
952         \lo arg1 arg2
953         \lo_list
954         \o arg1
955         \p
956         \password arg1
957         \prompt arg1 arg2
958         \pset arg1 arg2
959         \q
960         \reset
961         \s arg1
962         \set arg1 arg2 arg3 arg4 arg5 arg6 arg7
963         \setenv arg1 arg2
964         \sf whole_line
965         \sv whole_line
966         \t arg1
967         \T arg1
968         \timing arg1
969         \unset arg1
970         \w arg1
971         \watch arg1
972         \x arg1
973         -- \else here is eaten as part of OT_FILEPIPE argument
974         \w |/no/such/file \else
975         -- \endif here is eaten as part of whole-line argument
976         \! whole_line \endif
977         \z
978 \else
979         \echo 'should print #8-1'
980 \endif
981
982 -- :{?...} defined variable test
983 \set i 1
984 \if :{?i}
985   \echo '#9-1 ok, variable i is defined'
986 \else
987   \echo 'should not print #9-2'
988 \endif
989
990 \if :{?no_such_variable}
991   \echo 'should not print #10-1'
992 \else
993   \echo '#10-2 ok, variable no_such_variable is not defined'
994 \endif
995
996 SELECT :{?i} AS i_is_defined;
997
998 SELECT NOT :{?no_such_var} AS no_such_var_is_not_defined;
999
1000 -- SHOW_CONTEXT
1001
1002 \set SHOW_CONTEXT never
1003 do $$
1004 begin
1005   raise notice 'foo';
1006   raise exception 'bar';
1007 end $$;
1008
1009 \set SHOW_CONTEXT errors
1010 do $$
1011 begin
1012   raise notice 'foo';
1013   raise exception 'bar';
1014 end $$;
1015
1016 \set SHOW_CONTEXT always
1017 do $$
1018 begin
1019   raise notice 'foo';
1020   raise exception 'bar';
1021 end $$;
1022
1023 -- test printing and clearing the query buffer
1024 SELECT 1;
1025 \p
1026 SELECT 2 \r
1027 \p
1028 SELECT 3 \p
1029 UNION SELECT 4 \p
1030 UNION SELECT 5
1031 ORDER BY 1;
1032 \r
1033 \p
1034
1035 -- tests for special result variables
1036
1037 -- working query, 2 rows selected
1038 SELECT 1 AS stuff UNION SELECT 2;
1039 \echo 'error:' :ERROR
1040 \echo 'error code:' :SQLSTATE
1041 \echo 'number of rows:' :ROW_COUNT
1042
1043 -- syntax error
1044 SELECT 1 UNION;
1045 \echo 'error:' :ERROR
1046 \echo 'error code:' :SQLSTATE
1047 \echo 'number of rows:' :ROW_COUNT
1048 \echo 'last error message:' :LAST_ERROR_MESSAGE
1049 \echo 'last error code:' :LAST_ERROR_SQLSTATE
1050
1051 -- empty query
1052 ;
1053 \echo 'error:' :ERROR
1054 \echo 'error code:' :SQLSTATE
1055 \echo 'number of rows:' :ROW_COUNT
1056 -- must have kept previous values
1057 \echo 'last error message:' :LAST_ERROR_MESSAGE
1058 \echo 'last error code:' :LAST_ERROR_SQLSTATE
1059
1060 -- other query error
1061 DROP TABLE this_table_does_not_exist;
1062 \echo 'error:' :ERROR
1063 \echo 'error code:' :SQLSTATE
1064 \echo 'number of rows:' :ROW_COUNT
1065 \echo 'last error message:' :LAST_ERROR_MESSAGE
1066 \echo 'last error code:' :LAST_ERROR_SQLSTATE
1067
1068 -- nondefault verbosity error settings (except verbose, which is too unstable)
1069 \set VERBOSITY terse
1070 SELECT 1 UNION;
1071 \echo 'error:' :ERROR
1072 \echo 'error code:' :SQLSTATE
1073 \echo 'last error message:' :LAST_ERROR_MESSAGE
1074
1075 \set VERBOSITY sqlstate
1076 SELECT 1/0;
1077 \echo 'error:' :ERROR
1078 \echo 'error code:' :SQLSTATE
1079 \echo 'last error message:' :LAST_ERROR_MESSAGE
1080
1081 \set VERBOSITY default
1082
1083 -- working \gdesc
1084 SELECT 3 AS three, 4 AS four \gdesc
1085 \echo 'error:' :ERROR
1086 \echo 'error code:' :SQLSTATE
1087 \echo 'number of rows:' :ROW_COUNT
1088
1089 -- \gdesc with an error
1090 SELECT 4 AS \gdesc
1091 \echo 'error:' :ERROR
1092 \echo 'error code:' :SQLSTATE
1093 \echo 'number of rows:' :ROW_COUNT
1094 \echo 'last error message:' :LAST_ERROR_MESSAGE
1095 \echo 'last error code:' :LAST_ERROR_SQLSTATE
1096
1097 -- check row count for a cursor-fetched query
1098 \set FETCH_COUNT 10
1099 select unique2 from tenk1 order by unique2 limit 19;
1100 \echo 'error:' :ERROR
1101 \echo 'error code:' :SQLSTATE
1102 \echo 'number of rows:' :ROW_COUNT
1103
1104 -- cursor-fetched query with an error after the first group
1105 select 1/(15-unique2) from tenk1 order by unique2 limit 19;
1106 \echo 'error:' :ERROR
1107 \echo 'error code:' :SQLSTATE
1108 \echo 'number of rows:' :ROW_COUNT
1109 \echo 'last error message:' :LAST_ERROR_MESSAGE
1110 \echo 'last error code:' :LAST_ERROR_SQLSTATE
1111
1112 \unset FETCH_COUNT
1113
1114 create schema testpart;
1115 create role regress_partitioning_role;
1116
1117 alter schema testpart owner to regress_partitioning_role;
1118
1119 set role to regress_partitioning_role;
1120
1121 -- run test inside own schema and hide other partitions
1122 set search_path to testpart;
1123
1124 create table testtable_apple(logdate date);
1125 create table testtable_orange(logdate date);
1126 create index testtable_apple_index on testtable_apple(logdate);
1127 create index testtable_orange_index on testtable_orange(logdate);
1128
1129 create table testpart_apple(logdate date) partition by range(logdate);
1130 create table testpart_orange(logdate date) partition by range(logdate);
1131
1132 create index testpart_apple_index on testpart_apple(logdate);
1133 create index testpart_orange_index on testpart_orange(logdate);
1134
1135 -- only partition related object should be displayed
1136 \dP test*apple*
1137 \dPt test*apple*
1138 \dPi test*apple*
1139
1140 drop table testtable_apple;
1141 drop table testtable_orange;
1142 drop table testpart_apple;
1143 drop table testpart_orange;
1144
1145 create table parent_tab (id int) partition by range (id);
1146 create index parent_index on parent_tab (id);
1147 create table child_0_10 partition of parent_tab
1148   for values from (0) to (10);
1149 create table child_10_20 partition of parent_tab
1150   for values from (10) to (20);
1151 create table child_20_30 partition of parent_tab
1152   for values from (20) to (30);
1153 insert into parent_tab values (generate_series(0,29));
1154 create table child_30_40 partition of parent_tab
1155 for values from (30) to (40)
1156   partition by range(id);
1157 create table child_30_35 partition of child_30_40
1158   for values from (30) to (35);
1159 create table child_35_40 partition of child_30_40
1160    for values from (35) to (40);
1161 insert into parent_tab values (generate_series(30,39));
1162
1163 \dPt
1164 \dPi
1165
1166 \dP testpart.*
1167 \dP
1168
1169 \dPtn
1170 \dPin
1171 \dPn
1172 \dPn testpart.*
1173
1174 drop table parent_tab cascade;
1175
1176 drop schema testpart;
1177
1178 set search_path to default;
1179
1180 set role to default;
1181 drop role regress_partitioning_role;
1182
1183 -- \d on toast table (use pg_statistic's toast table, which has a known name)
1184 \d pg_toast.pg_toast_2619