1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
|
---input---
regression=# select foo;
ERROR: column "foo" does not exist
CONTEXT: PL/pgSQL function "test1" while casting return value to function's return type
LINE 1: select foo;
^
regression=# \q
peter@localhost testdb=> \a \t \x
Output format is aligned.
Tuples only is off.
Expanded display is on.
regression=# select '\x';
WARNING: nonstandard use of escape in a string literal
LINE 1: select '\x';
^
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
?column?
----------
x
(1 row)
regression=# select E'\x';
piro=> \set foo 30;
piro=> select * from test where foo <= :foo;
foo | bar
-----+-----
10 |
20 |
(2 rows)
testdb=> \set foo 'my_table'
testdb=> SELECT * FROM :"foo";
testdb=> \set content `cat my_file.txt`
testdb=> INSERT INTO my_table VALUES (:'content');
regression=# select (
regression(# 1);
?column?
----------
1
(1 row)
piro=> select (
piro(> '
piro'> ' || $$
piro$> $$)
piro-> from "
piro"> foo";
ERROR: relation "
foo" does not exist
LINE 5: from "
^
testdb=> CREATE TABLE my_table (
first integer not null default 0,
second text) ; -- end of command
CREATE TABLE
-- Table output
=# SELECT '0x10'::mpz AS "hex", '10'::mpz AS "dec",
-# '010'::mpz AS oct, '0b10'::mpz AS bin;
hex | dec | oct | bin
-----+-----+-----+-----
16 | 10 | 8 | 2
(1 row)
-- One field output
regression=# select schemaname from pg_tables limit 3;
schemaname
------------
pg_catalog
pg_catalog
pg_catalog
(3 rows)
-- TODO: prompt in multiline comments still not handled correctly
test=> select 1 /* multiline
test*> and 2 /* and 3 */
test*> end comment */, 2;
?column? | ?column?
----------+----------
1 | 2
=# select 10.0, 1e-6, 1E+6;
?column? | ?column? | ?column?
----------+----------+----------
10.0 | 0.000001 | 1000000
(1 row)
regression=# begin;
BEGIN
regression=# create table asdf (foo serial primary key);
NOTICE: CREATE TABLE will create implicit sequence "asdf_foo_seq" for serial column "asdf.foo"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "asdf_pkey" for table "asdf"
CREATE TABLE
regression=# insert into asdf values (10) returning foo;
foo
-----
10
(1 row)
INSERT 0 1
regression=# ROLLBACK ;
ROLLBACK
=> EXPLAIN SELECT * FROM tenk1
-> WHERE unique1 < 100; -- Don't take -> in the plan as a prompt
QUERY PLAN
------------------------------------------------------------------------------
Bitmap Heap Scan on tenk1 (cost=2.37..232.35 rows=106 width=244)
Recheck Cond: (unique1 < 100)
-> Bitmap Index Scan on tenk1_unique1 (cost=0.00..2.37 rows=106 width=0)
Index Cond: (unique1 < 100)
-- don't swallow the end of a malformed line
test=> select 1,
'this line must be emitted'
---tokens---
'regression=#' Generic.Prompt
' ' Text
'select' Keyword
' ' Text
'foo' Name
';' Punctuation
'\n' Text
'ERROR:' Generic.Strong
' column "foo" does not exist\n' Generic.Error
'CONTEXT:' Generic.Strong
' PL/pgSQL function "test1" while casting return value to function\'s return type\n' Generic.Error
'LINE 1:' Generic.Strong
' select foo;\n' Generic.Error
' ^\n' Generic.Error
'regression=#' Generic.Prompt
' ' Text
'\\q' Keyword.Pseudo
'\n' Text
'\n' Generic.Output
'peter@localhost testdb=>' Generic.Prompt
' ' Text
'\\a' Keyword.Pseudo
' ' Text
'\\t' Keyword.Pseudo
' ' Text
'\\x' Keyword.Pseudo
'\n' Text
'Output format is aligned.\n' Generic.Output
'Tuples only is off.\n' Generic.Output
'Expanded display is on.\n' Generic.Output
'\n' Generic.Output
'regression=#' Generic.Prompt
' ' Text
'select' Keyword
' ' Text
"'" Literal.String.Single
'\\x' Literal.String.Single
"'" Literal.String.Single
';' Punctuation
'\n' Text
'WARNING:' Generic.Strong
' nonstandard use of escape in a string literal\n' Generic.Output
'LINE 1:' Generic.Strong
" select '\\x';\n" Generic.Output
' ^\n' Generic.Output
'HINT:' Generic.Strong
" Use the escape string syntax for escapes, e.g., E'\\r\\n'.\n" Generic.Output
' ?column? \n' Generic.Output
'----------\n' Generic.Output
' x\n' Generic.Output
'(1 row)\n' Generic.Output
'\n' Generic.Output
'regression=#' Generic.Prompt
' ' Text
'select' Keyword
' ' Text
'E' Literal.String.Affix
"'" Literal.String.Single
'\\x' Literal.String.Single
"'" Literal.String.Single
';' Punctuation
'\n' Text
'\n' Generic.Output
'piro=>' Generic.Prompt
' ' Text
'\\set' Keyword.Pseudo
' ' Text
'foo' Literal.String.Symbol
' ' Text
'30;' Literal.String.Symbol
'\n' Text
'piro=>' Generic.Prompt
' ' Text
'select' Keyword
' ' Text
'*' Operator
' ' Text
'from' Keyword
' ' Text
'test' Name
' ' Text
'where' Keyword
' ' Text
'foo' Name
' ' Text
'<=' Operator
' ' Text
':foo' Name.Variable
';' Punctuation
'\n' Text
' foo | bar \n' Generic.Output
'-----+-----\n' Generic.Output
' 10 | \n' Generic.Output
' 20 | \n' Generic.Output
'(2 rows)\n' Generic.Output
'\n' Generic.Output
'testdb=>' Generic.Prompt
' ' Text
'\\set' Keyword.Pseudo
' ' Text
'foo' Literal.String.Symbol
' ' Text
"'my_table'" Literal.String.Single
'\n' Text
'testdb=>' Generic.Prompt
' ' Text
'SELECT' Keyword
' ' Text
'*' Operator
' ' Text
'FROM' Keyword
' ' Text
':"foo"' Name.Variable
';' Punctuation
'\n' Text
'\n' Generic.Output
'testdb=>' Generic.Prompt
' ' Text
'\\set' Keyword.Pseudo
' ' Text
'content' Literal.String.Symbol
' ' Text
'`cat my_file.txt`' Literal.String.Backtick
'\n' Text
'testdb=>' Generic.Prompt
' ' Text
'INSERT' Keyword
' ' Text
'INTO' Keyword
' ' Text
'my_table' Name
' ' Text
'VALUES' Keyword
' ' Text
'(' Punctuation
":'content'" Name.Variable
')' Punctuation
';' Punctuation
'\n' Text
'\n' Generic.Output
'regression=#' Generic.Prompt
' ' Text
'select' Keyword
' ' Text
'(' Punctuation
'\n' Text
'regression(#' Generic.Prompt
' ' Text
'1' Literal.Number.Float
')' Punctuation
';' Punctuation
'\n' Text
' ?column? \n' Generic.Output
'----------\n' Generic.Output
' 1\n' Generic.Output
'(1 row)\n' Generic.Output
'\n' Generic.Output
'piro=>' Generic.Prompt
' ' Text
'select' Keyword
' ' Text
'(' Punctuation
'\n' Text
'piro(>' Generic.Prompt
' ' Text
"'" Literal.String.Single
'\n' Literal.String.Single
"piro'>" Generic.Prompt
' ' Literal.String.Single
"'" Literal.String.Single
' ' Text
'||' Operator
' ' Text
'$' Literal.String
'$' Literal.String
'\n' Literal.String
'piro$>' Generic.Prompt
' ' Literal.String
'$' Literal.String
'$' Literal.String
')' Punctuation
'\n' Text
'piro->' Generic.Prompt
' ' Text
'from' Keyword
' ' Text
'"' Literal.String.Name
'\n' Literal.String.Name
'piro">' Generic.Prompt
' foo' Literal.String.Name
'"' Literal.String.Name
';' Punctuation
'\n' Text
'ERROR:' Generic.Strong
' relation "\n' Generic.Error
'foo" does not exist\n' Generic.Error
'LINE 5:' Generic.Strong
' from "\n' Generic.Error
' ^\n' Generic.Error
'\n' Generic.Error
'testdb=>' Generic.Prompt
' ' Text
'CREATE' Keyword
' ' Text
'TABLE' Keyword
' ' Text
'my_table' Name
' ' Text
'(' Punctuation
'\n' Text
'first' Keyword
' ' Text
'integer' Name.Builtin
' ' Text
'not' Keyword
' ' Text
'null' Keyword
' ' Text
'default' Keyword
' ' Text
'0' Literal.Number.Float
',' Punctuation
'\n' Text
'second' Keyword
' ' Text
'text' Name.Builtin
')' Punctuation
' ' Text
';' Punctuation
' ' Text
'-- end of command\n' Comment.Single
'CREATE TABLE\n' Generic.Output
'\n' Generic.Output
'-- Table output\n' Generic.Output
'=#' Generic.Prompt
' ' Text
'SELECT' Keyword
' ' Text
"'" Literal.String.Single
'0x10' Literal.String.Single
"'" Literal.String.Single
'::' Operator
'mpz' Name
' ' Text
'AS' Keyword
' ' Text
'"' Literal.String.Name
'hex' Literal.String.Name
'"' Literal.String.Name
',' Punctuation
' ' Text
"'" Literal.String.Single
'10' Literal.String.Single
"'" Literal.String.Single
'::' Operator
'mpz' Name
' ' Text
'AS' Keyword
' ' Text
'"' Literal.String.Name
'dec' Literal.String.Name
'"' Literal.String.Name
',' Punctuation
'\n' Text
'-#' Generic.Prompt
' ' Text
"'" Literal.String.Single
'010' Literal.String.Single
"'" Literal.String.Single
'::' Operator
'mpz' Name
' ' Text
'AS' Keyword
' ' Text
'oct' Name
',' Punctuation
' ' Text
"'" Literal.String.Single
'0b10' Literal.String.Single
"'" Literal.String.Single
'::' Operator
'mpz' Name
' ' Text
'AS' Keyword
' ' Text
'bin' Name
';' Punctuation
'\n' Text
' hex | dec | oct | bin\n' Generic.Output
'-----+-----+-----+-----\n' Generic.Output
' 16 | 10 | 8 | 2\n' Generic.Output
'(1 row)\n' Generic.Output
'\n' Generic.Output
'-- One field output\n' Generic.Output
'regression=#' Generic.Prompt
' ' Text
'select' Keyword
' ' Text
'schemaname' Name
' ' Text
'from' Keyword
' ' Text
'pg_tables' Name
' ' Text
'limit' Keyword
' ' Text
'3' Literal.Number.Float
';' Punctuation
'\n' Text
' schemaname \n' Generic.Output
'------------\n' Generic.Output
' pg_catalog\n' Generic.Output
' pg_catalog\n' Generic.Output
' pg_catalog\n' Generic.Output
'(3 rows)\n' Generic.Output
'\n' Generic.Output
'-- TODO: prompt in multiline comments still not handled correctly\n' Generic.Output
'test=>' Generic.Prompt
' ' Text
'select' Keyword
' ' Text
'1' Literal.Number.Float
' ' Text
'/*' Comment.Multiline
' multiline\ntest' Comment.Multiline
'*' Comment.Multiline
'> and 2 ' Comment.Multiline
'/*' Comment.Multiline
' and 3 ' Comment.Multiline
'*/' Comment.Multiline
'\ntest' Comment.Multiline
'*' Comment.Multiline
'> end comment ' Comment.Multiline
'*/' Comment.Multiline
',' Punctuation
' ' Text
'2' Literal.Number.Float
';' Punctuation
'\n' Text
' ?column? | ?column? \n' Generic.Output
'----------+----------\n' Generic.Output
' 1 | 2\n' Generic.Output
'\n' Generic.Output
'=#' Generic.Prompt
' ' Text
'select' Keyword
' ' Text
'10.0' Literal.Number.Float
',' Punctuation
' ' Text
'1e-6' Literal.Number.Float
',' Punctuation
' ' Text
'1E+6' Literal.Number.Float
';' Punctuation
'\n' Text
' ?column? | ?column? | ?column? \n' Generic.Output
'----------+----------+----------\n' Generic.Output
' 10.0 | 0.000001 | 1000000\n' Generic.Output
'(1 row)\n' Generic.Output
'\n' Generic.Output
'regression=#' Generic.Prompt
' ' Text
'begin' Keyword
';' Punctuation
'\n' Text
'BEGIN\n' Generic.Output
'regression=#' Generic.Prompt
' ' Text
'create' Keyword
' ' Text
'table' Keyword
' ' Text
'asdf' Name
' ' Text
'(' Punctuation
'foo' Name
' ' Text
'serial' Name.Builtin
' ' Text
'primary' Keyword
' ' Text
'key' Keyword
')' Punctuation
';' Punctuation
'\n' Text
'NOTICE:' Generic.Strong
' CREATE TABLE will create implicit sequence "asdf_foo_seq" for serial column "asdf.foo"\n' Generic.Output
'NOTICE:' Generic.Strong
' CREATE TABLE / PRIMARY KEY will create implicit index "asdf_pkey" for table "asdf"\n' Generic.Output
'CREATE TABLE\n' Generic.Output
'regression=#' Generic.Prompt
' ' Text
'insert' Keyword
' ' Text
'into' Keyword
' ' Text
'asdf' Name
' ' Text
'values' Keyword
' ' Text
'(' Punctuation
'10' Literal.Number.Float
')' Punctuation
' ' Text
'returning' Keyword
' ' Text
'foo' Name
';' Punctuation
'\n' Text
' foo \n' Generic.Output
'-----\n' Generic.Output
' 10\n' Generic.Output
'(1 row)\n' Generic.Output
'\n' Generic.Output
'INSERT 0 1\n' Generic.Output
'regression=#' Generic.Prompt
' ' Text
'ROLLBACK' Keyword
' ' Text
';' Punctuation
'\n' Text
'ROLLBACK\n' Generic.Output
'\n' Generic.Output
'=>' Generic.Prompt
' ' Text
'EXPLAIN' Keyword
' ' Text
'SELECT' Keyword
' ' Text
'*' Operator
' ' Text
'FROM' Keyword
' ' Text
'tenk1' Name
'\n' Text
'->' Generic.Prompt
' ' Text
'WHERE' Keyword
' ' Text
'unique1' Name
' ' Text
'<' Operator
' ' Text
'100' Literal.Number.Float
';' Punctuation
' ' Text
"-- Don't take -> in the plan as a prompt\n" Comment.Single
'\n' Generic.Output
' QUERY PLAN\n' Generic.Output
'------------------------------------------------------------------------------\n' Generic.Output
' Bitmap Heap Scan on tenk1 (cost=2.37..232.35 rows=106 width=244)\n' Generic.Output
' Recheck Cond: (unique1 < 100)\n' Generic.Output
' -> Bitmap Index Scan on tenk1_unique1 (cost=0.00..2.37 rows=106 width=0)\n' Generic.Output
' Index Cond: (unique1 < 100)\n' Generic.Output
'\n' Generic.Output
'\n' Generic.Output
"-- don't swallow the end of a malformed line\n" Generic.Output
'test=>' Generic.Prompt
' ' Text
'select' Keyword
' ' Text
'1' Literal.Number.Float
',' Punctuation
'\n' Text
"'" Literal.String.Single
'this line must be emitted' Literal.String.Single
"'" Literal.String.Single
'\n' Text
|