@@ -53,6 +53,22 @@ ERROR: malformed record literal: "(Joe,,)"
5353LINE 1: select '(Joe,,)'::fullname;
5454 ^
5555DETAIL: Too many columns.
56+ select '[]'::fullname; -- bad
57+ ERROR: malformed record literal: "[]"
58+ LINE 1: select '[]'::fullname;
59+ ^
60+ DETAIL: Missing left parenthesis.
61+ select ' (Joe,Blow) '::fullname; -- ok, extra whitespace
62+ fullname
63+ ------------
64+ (Joe,Blow)
65+ (1 row)
66+
67+ select '(Joe,Blow) /'::fullname; -- bad
68+ ERROR: malformed record literal: "(Joe,Blow) /"
69+ LINE 1: select '(Joe,Blow) /'::fullname;
70+ ^
71+ DETAIL: Junk after right parenthesis.
5672create temp table quadtable(f1 int, q quad);
5773insert into quadtable values (1, ((3.3,4.4),(5.5,6.6)));
5874insert into quadtable values (2, ((null,4.4),(5.5,6.6)));
@@ -369,6 +385,290 @@ LINE 1: select * from cc order by f1;
369385 ^
370386HINT: Use an explicit ordering operator or modify the query.
371387--
388+ -- Tests for record_{eq,cmp}
389+ --
390+ create type testtype1 as (a int, b int);
391+ -- all true
392+ select row(1, 2)::testtype1 < row(1, 3)::testtype1;
393+ ?column?
394+ ----------
395+ t
396+ (1 row)
397+
398+ select row(1, 2)::testtype1 <= row(1, 3)::testtype1;
399+ ?column?
400+ ----------
401+ t
402+ (1 row)
403+
404+ select row(1, 2)::testtype1 = row(1, 2)::testtype1;
405+ ?column?
406+ ----------
407+ t
408+ (1 row)
409+
410+ select row(1, 2)::testtype1 <> row(1, 3)::testtype1;
411+ ?column?
412+ ----------
413+ t
414+ (1 row)
415+
416+ select row(1, 3)::testtype1 >= row(1, 2)::testtype1;
417+ ?column?
418+ ----------
419+ t
420+ (1 row)
421+
422+ select row(1, 3)::testtype1 > row(1, 2)::testtype1;
423+ ?column?
424+ ----------
425+ t
426+ (1 row)
427+
428+ -- all false
429+ select row(1, -2)::testtype1 < row(1, -3)::testtype1;
430+ ?column?
431+ ----------
432+ f
433+ (1 row)
434+
435+ select row(1, -2)::testtype1 <= row(1, -3)::testtype1;
436+ ?column?
437+ ----------
438+ f
439+ (1 row)
440+
441+ select row(1, -2)::testtype1 = row(1, -3)::testtype1;
442+ ?column?
443+ ----------
444+ f
445+ (1 row)
446+
447+ select row(1, -2)::testtype1 <> row(1, -2)::testtype1;
448+ ?column?
449+ ----------
450+ f
451+ (1 row)
452+
453+ select row(1, -3)::testtype1 >= row(1, -2)::testtype1;
454+ ?column?
455+ ----------
456+ f
457+ (1 row)
458+
459+ select row(1, -3)::testtype1 > row(1, -2)::testtype1;
460+ ?column?
461+ ----------
462+ f
463+ (1 row)
464+
465+ -- true, but see *< below
466+ select row(1, -2)::testtype1 < row(1, 3)::testtype1;
467+ ?column?
468+ ----------
469+ t
470+ (1 row)
471+
472+ -- mismatches
473+ create type testtype3 as (a int, b text);
474+ select row(1, 2)::testtype1 < row(1, 'abc')::testtype3;
475+ ERROR: cannot compare dissimilar column types integer and text at record column 2
476+ select row(1, 2)::testtype1 <> row(1, 'abc')::testtype3;
477+ ERROR: cannot compare dissimilar column types integer and text at record column 2
478+ create type testtype5 as (a int);
479+ select row(1, 2)::testtype1 < row(1)::testtype5;
480+ ERROR: cannot compare record types with different numbers of columns
481+ select row(1, 2)::testtype1 <> row(1)::testtype5;
482+ ERROR: cannot compare record types with different numbers of columns
483+ -- non-comparable types
484+ create type testtype6 as (a int, b point);
485+ select row(1, '(1,2)')::testtype6 < row(1, '(1,3)')::testtype6;
486+ ERROR: could not identify a comparison function for type point
487+ select row(1, '(1,2)')::testtype6 <> row(1, '(1,3)')::testtype6;
488+ ERROR: could not identify an equality operator for type point
489+ drop type testtype1, testtype3, testtype5, testtype6;
490+ --
491+ -- Tests for record_image_{eq,cmp}
492+ --
493+ create type testtype1 as (a int, b int);
494+ -- all true
495+ select row(1, 2)::testtype1 *< row(1, 3)::testtype1;
496+ ?column?
497+ ----------
498+ t
499+ (1 row)
500+
501+ select row(1, 2)::testtype1 *<= row(1, 3)::testtype1;
502+ ?column?
503+ ----------
504+ t
505+ (1 row)
506+
507+ select row(1, 2)::testtype1 *= row(1, 2)::testtype1;
508+ ?column?
509+ ----------
510+ t
511+ (1 row)
512+
513+ select row(1, 2)::testtype1 *<> row(1, 3)::testtype1;
514+ ?column?
515+ ----------
516+ t
517+ (1 row)
518+
519+ select row(1, 3)::testtype1 *>= row(1, 2)::testtype1;
520+ ?column?
521+ ----------
522+ t
523+ (1 row)
524+
525+ select row(1, 3)::testtype1 *> row(1, 2)::testtype1;
526+ ?column?
527+ ----------
528+ t
529+ (1 row)
530+
531+ -- all false
532+ select row(1, -2)::testtype1 *< row(1, -3)::testtype1;
533+ ?column?
534+ ----------
535+ f
536+ (1 row)
537+
538+ select row(1, -2)::testtype1 *<= row(1, -3)::testtype1;
539+ ?column?
540+ ----------
541+ f
542+ (1 row)
543+
544+ select row(1, -2)::testtype1 *= row(1, -3)::testtype1;
545+ ?column?
546+ ----------
547+ f
548+ (1 row)
549+
550+ select row(1, -2)::testtype1 *<> row(1, -2)::testtype1;
551+ ?column?
552+ ----------
553+ f
554+ (1 row)
555+
556+ select row(1, -3)::testtype1 *>= row(1, -2)::testtype1;
557+ ?column?
558+ ----------
559+ f
560+ (1 row)
561+
562+ select row(1, -3)::testtype1 *> row(1, -2)::testtype1;
563+ ?column?
564+ ----------
565+ f
566+ (1 row)
567+
568+ -- This returns the "wrong" order because record_image_cmp works on
569+ -- unsigned datums without knowing about the actual data type.
570+ select row(1, -2)::testtype1 *< row(1, 3)::testtype1;
571+ ?column?
572+ ----------
573+ f
574+ (1 row)
575+
576+ -- other types
577+ create type testtype2 as (a smallint, b bool); -- byval different sizes
578+ select row(1, true)::testtype2 *< row(2, true)::testtype2;
579+ ?column?
580+ ----------
581+ t
582+ (1 row)
583+
584+ select row(-2, true)::testtype2 *< row(-1, true)::testtype2;
585+ ?column?
586+ ----------
587+ t
588+ (1 row)
589+
590+ select row(0, false)::testtype2 *< row(0, true)::testtype2;
591+ ?column?
592+ ----------
593+ t
594+ (1 row)
595+
596+ select row(0, false)::testtype2 *<> row(0, true)::testtype2;
597+ ?column?
598+ ----------
599+ t
600+ (1 row)
601+
602+ create type testtype3 as (a int, b text); -- variable length
603+ select row(1, 'abc')::testtype3 *< row(1, 'abd')::testtype3;
604+ ?column?
605+ ----------
606+ t
607+ (1 row)
608+
609+ select row(1, 'abc')::testtype3 *< row(1, 'abcd')::testtype3;
610+ ?column?
611+ ----------
612+ t
613+ (1 row)
614+
615+ select row(1, 'abc')::testtype3 *> row(1, 'abd')::testtype3;
616+ ?column?
617+ ----------
618+ f
619+ (1 row)
620+
621+ select row(1, 'abc')::testtype3 *<> row(1, 'abd')::testtype3;
622+ ?column?
623+ ----------
624+ t
625+ (1 row)
626+
627+ create type testtype4 as (a int, b point); -- by ref, fixed length
628+ select row(1, '(1,2)')::testtype4 *< row(1, '(1,3)')::testtype4;
629+ ?column?
630+ ----------
631+ t
632+ (1 row)
633+
634+ select row(1, '(1,2)')::testtype4 *<> row(1, '(1,3)')::testtype4;
635+ ?column?
636+ ----------
637+ t
638+ (1 row)
639+
640+ -- mismatches
641+ select row(1, 2)::testtype1 *< row(1, 'abc')::testtype3;
642+ ERROR: cannot compare dissimilar column types integer and text at record column 2
643+ select row(1, 2)::testtype1 *<> row(1, 'abc')::testtype3;
644+ ERROR: cannot compare dissimilar column types integer and text at record column 2
645+ create type testtype5 as (a int);
646+ select row(1, 2)::testtype1 *< row(1)::testtype5;
647+ ERROR: cannot compare record types with different numbers of columns
648+ select row(1, 2)::testtype1 *<> row(1)::testtype5;
649+ ERROR: cannot compare record types with different numbers of columns
650+ -- non-comparable types
651+ create type testtype6 as (a int, b point);
652+ select row(1, '(1,2)')::testtype6 *< row(1, '(1,3)')::testtype6;
653+ ?column?
654+ ----------
655+ t
656+ (1 row)
657+
658+ select row(1, '(1,2)')::testtype6 *>= row(1, '(1,3)')::testtype6;
659+ ?column?
660+ ----------
661+ f
662+ (1 row)
663+
664+ select row(1, '(1,2)')::testtype6 *<> row(1, '(1,3)')::testtype6;
665+ ?column?
666+ ----------
667+ t
668+ (1 row)
669+
670+ drop type testtype1, testtype2, testtype3, testtype4, testtype5, testtype6;
671+ --
372672-- Test case derived from bug #5716: check multiple uses of a rowtype result
373673--
374674BEGIN;
0 commit comments