@@ -388,23 +388,267 @@ SELECT $1 \bind 3 \sendpipeline
388
388
389
389
\endpipeline
390
390
--
391
- -- Pipeline errors
391
+ -- Tests pipelining queries with ';'
392
392
--
393
- -- \endpipeline outside of pipeline should fail
393
+ -- Single query sent with ';'
394
+ \startpipeline
395
+ SELECT 1;
394
396
\endpipeline
395
- cannot send pipeline when not in pipeline mode
396
- -- Query using simple protocol should not be sent and should leave the
397
- -- pipeline usable.
397
+ ?column?
398
+ ----------
399
+ 1
400
+ (1 row)
401
+
402
+ -- Multiple queries sent with ';'
403
+ \startpipeline
404
+ SELECT 1;
405
+ SELECT 2;
406
+ SELECT 3;
407
+ \endpipeline
408
+ ?column?
409
+ ----------
410
+ 1
411
+ (1 row)
412
+
413
+ ?column?
414
+ ----------
415
+ 2
416
+ (1 row)
417
+
418
+ ?column?
419
+ ----------
420
+ 3
421
+ (1 row)
422
+
423
+ -- Multiple queries on the same line can be piped with ';'
424
+ \startpipeline
425
+ SELECT 1; SELECT 2; SELECT 3
426
+ ;
427
+ \endpipeline
428
+ ?column?
429
+ ----------
430
+ 1
431
+ (1 row)
432
+
433
+ ?column?
434
+ ----------
435
+ 2
436
+ (1 row)
437
+
438
+ ?column?
439
+ ----------
440
+ 3
441
+ (1 row)
442
+
443
+ -- Test \flush with queries piped with ';'
444
+ \startpipeline
445
+ \flush
446
+ SELECT 1;
447
+ \flush
448
+ SELECT 2;
449
+ SELECT 3;
450
+ \endpipeline
451
+ ?column?
452
+ ----------
453
+ 1
454
+ (1 row)
455
+
456
+ ?column?
457
+ ----------
458
+ 2
459
+ (1 row)
460
+
461
+ ?column?
462
+ ----------
463
+ 3
464
+ (1 row)
465
+
466
+ -- Send multiple syncs with queries piped with ';'
467
+ \startpipeline
468
+ \echo :PIPELINE_COMMAND_COUNT
469
+ 0
470
+ \echo :PIPELINE_SYNC_COUNT
471
+ 0
472
+ \echo :PIPELINE_RESULT_COUNT
473
+ 0
474
+ SELECT 1;
475
+ \syncpipeline
476
+ \syncpipeline
477
+ SELECT 2;
478
+ \syncpipeline
479
+ SELECT 3;
480
+ \echo :PIPELINE_COMMAND_COUNT
481
+ 1
482
+ \echo :PIPELINE_SYNC_COUNT
483
+ 3
484
+ \echo :PIPELINE_RESULT_COUNT
485
+ 2
486
+ \endpipeline
487
+ ?column?
488
+ ----------
489
+ 1
490
+ (1 row)
491
+
492
+ ?column?
493
+ ----------
494
+ 2
495
+ (1 row)
496
+
497
+ ?column?
498
+ ----------
499
+ 3
500
+ (1 row)
501
+
502
+ -- Mix queries piped with ';' and \sendpipeline
398
503
\startpipeline
399
504
SELECT 1;
400
- PQsendQuery not allowed in pipeline mode
401
505
SELECT $1 \bind 'val1' \sendpipeline
506
+ SELECT $1, $2 \bind 'val2' 'val3' \sendpipeline
507
+ SELECT 2;
508
+ \endpipeline
509
+ ?column?
510
+ ----------
511
+ 1
512
+ (1 row)
513
+
514
+ ?column?
515
+ ----------
516
+ val1
517
+ (1 row)
518
+
519
+ ?column? | ?column?
520
+ ----------+----------
521
+ val2 | val3
522
+ (1 row)
523
+
524
+ ?column?
525
+ ----------
526
+ 2
527
+ (1 row)
528
+
529
+ -- Piping a query with ';' will replace the unnamed prepared statement
530
+ \startpipeline
531
+ SELECT $1 \parse ''
532
+ SELECT 1;
533
+ \bind_named ''
534
+ \endpipeline
535
+ ?column?
536
+ ----------
537
+ 1
538
+ (1 row)
539
+
540
+ -- An extended query can be piped by a ';' after a newline
541
+ \startpipeline
542
+ SELECT $1 \bind 1
543
+ ;
544
+ SELECT 2;
545
+ \endpipeline
546
+ ?column?
547
+ ----------
548
+ 1
549
+ (1 row)
550
+
551
+ ?column?
552
+ ----------
553
+ 2
554
+ (1 row)
555
+
556
+ -- COPY FROM STDIN, using ';'
557
+ \startpipeline
558
+ SELECT 'val1';
559
+ COPY psql_pipeline FROM STDIN;
560
+ \endpipeline
561
+ ?column?
562
+ ----------
563
+ val1
564
+ (1 row)
565
+
566
+ -- COPY FROM STDIN with \flushrequest + \getresults, using ';'
567
+ \startpipeline
568
+ SELECT 'val1';
569
+ COPY psql_pipeline FROM STDIN;
570
+ \flushrequest
571
+ \getresults
572
+ ?column?
573
+ ----------
574
+ val1
575
+ (1 row)
576
+
577
+ message type 0x5a arrived from server while idle
578
+ \endpipeline
579
+ -- COPY FROM STDIN with \syncpipeline + \getresults, using ';'
580
+ \startpipeline
581
+ SELECT 'val1';
582
+ COPY psql_pipeline FROM STDIN;
583
+ \syncpipeline
584
+ \getresults
585
+ ?column?
586
+ ----------
587
+ val1
588
+ (1 row)
589
+
402
590
\endpipeline
591
+ -- COPY TO STDOUT, using ';'
592
+ \startpipeline
593
+ SELECT 'val1';
594
+ copy psql_pipeline TO STDOUT;
595
+ \endpipeline
596
+ ?column?
597
+ ----------
598
+ val1
599
+ (1 row)
600
+
601
+ 1 \N
602
+ 2 test2
603
+ 3 test3
604
+ 4 test4
605
+ 20 test2
606
+ 30 test3
607
+ 40 test4
608
+ -- COPY TO STDOUT with \flushrequest + \getresults, using ';'
609
+ \startpipeline
610
+ SELECT 'val1';
611
+ copy psql_pipeline TO STDOUT;
612
+ \flushrequest
613
+ \getresults
403
614
?column?
404
615
----------
405
616
val1
406
617
(1 row)
407
618
619
+ 1 \N
620
+ 2 test2
621
+ 3 test3
622
+ 4 test4
623
+ 20 test2
624
+ 30 test3
625
+ 40 test4
626
+ \endpipeline
627
+ -- COPY TO STDOUT with \syncpipeline + \getresults, using ';'
628
+ \startpipeline
629
+ SELECT 'val1';
630
+ copy psql_pipeline TO STDOUT;
631
+ \syncpipeline
632
+ \getresults
633
+ ?column?
634
+ ----------
635
+ val1
636
+ (1 row)
637
+
638
+ 1 \N
639
+ 2 test2
640
+ 3 test3
641
+ 4 test4
642
+ 20 test2
643
+ 30 test3
644
+ 40 test4
645
+ \endpipeline
646
+ --
647
+ -- Pipeline errors
648
+ --
649
+ -- \endpipeline outside of pipeline should fail
650
+ \endpipeline
651
+ cannot send pipeline when not in pipeline mode
408
652
-- After an aborted pipeline, commands after a \syncpipeline should be
409
653
-- displayed.
410
654
\startpipeline
@@ -425,6 +669,13 @@ SELECT \bind 'val1' \sendpipeline
425
669
SELECT $1 \bind 'val1' \sendpipeline
426
670
\endpipeline
427
671
ERROR: bind message supplies 1 parameters, but prepared statement "" requires 0
672
+ -- Using ';' with a parameter will trigger an incorrect parameter error and
673
+ -- abort the pipeline
674
+ \startpipeline
675
+ SELECT $1;
676
+ SELECT 1;
677
+ \endpipeline
678
+ ERROR: bind message supplies 0 parameters, but prepared statement "" requires 1
428
679
-- An explicit transaction with an error needs to be rollbacked after
429
680
-- the pipeline.
430
681
\startpipeline
@@ -435,12 +686,11 @@ ROLLBACK \bind \sendpipeline
435
686
ERROR: duplicate key value violates unique constraint "psql_pipeline_pkey"
436
687
DETAIL: Key (a)=(1) already exists.
437
688
ROLLBACK;
438
- -- \watch sends a simple query, something not allowed within a pipeline.
689
+ -- \watch is not allowed within a pipeline.
439
690
\startpipeline
440
691
SELECT \bind \sendpipeline
441
692
\watch 1
442
- PQsendQuery not allowed in pipeline mode
443
-
693
+ \watch not allowed in pipeline mode
444
694
\endpipeline
445
695
--
446
696
(1 row)
@@ -530,7 +780,7 @@ SELECT COUNT(*) FROM psql_pipeline \bind \sendpipeline
530
780
531
781
count
532
782
-------
533
- 4
783
+ 7
534
784
(1 row)
535
785
536
786
-- After an error, pipeline is aborted and requires \syncpipeline to be
@@ -617,11 +867,11 @@ select 1;
617
867
-- Error messages accumulate and are repeated.
618
868
\startpipeline
619
869
SELECT 1 \bind \sendpipeline
620
- SELECT 1;
621
- PQsendQuery not allowed in pipeline mode
622
- SELECT 1;
623
- PQsendQuery not allowed in pipeline mode
624
- PQsendQuery not allowed in pipeline mode
870
+ \gdesc
871
+ synchronous command execution functions are not allowed in pipeline mode
872
+ \gdesc
873
+ synchronous command execution functions are not allowed in pipeline mode
874
+ synchronous command execution functions are not allowed in pipeline mode
625
875
\endpipeline
626
876
?column?
627
877
----------
0 commit comments