diff --git a/pkg/sql/logictest/testdata/logic_test/refcursor b/pkg/sql/logictest/testdata/logic_test/refcursor index 7084890aafa8..56fd0750201c 100644 --- a/pkg/sql/logictest/testdata/logic_test/refcursor +++ b/pkg/sql/logictest/testdata/logic_test/refcursor @@ -391,4 +391,78 @@ NULL a NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL foo NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL foo NULL NULL NULL NULL NULL NULL NULL NULL +# REFCURSOR doesn't support any comparisons (with an exception mentioned below). +subtest comparisons + +# TODO(drewk): The error code should be 42883. +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR = 'foo'::REFCURSOR; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR = 'foo'::TEXT; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR = NULL; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR < 'foo'::REFCURSOR; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR < 'foo'::TEXT; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR < NULL; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR > 'foo'::REFCURSOR; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR > 'foo'::TEXT; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR > NULL; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR <= 'foo'::REFCURSOR; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR <= 'foo'::TEXT; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR <= NULL; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR >= 'foo'::REFCURSOR; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR >= 'foo'::TEXT; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR >= NULL; + +# TODO(drewk): Postgres allows this case. +statement error pgcode 42883 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR IS NULL; + +statement error pgcode 42883 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR IS NOT NULL; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR IS DISTINCT FROM 'foo'::REFCURSOR; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR IS DISTINCT FROM 'foo'::TEXT; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR IS DISTINCT FROM NULL; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR IS NOT DISTINCT FROM 'foo'::REFCURSOR; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR IS NOT DISTINCT FROM 'foo'::TEXT; + +statement error pgcode 22023 pq: unsupported comparison operator +SELECT 'foo'::REFCURSOR IS NOT DISTINCT FROM NULL; + subtest end diff --git a/pkg/sql/sem/tree/type_check.go b/pkg/sql/sem/tree/type_check.go index cbef0101ba1b..abd896057bdf 100644 --- a/pkg/sql/sem/tree/type_check.go +++ b/pkg/sql/sem/tree/type_check.go @@ -941,6 +941,14 @@ func (expr *ComparisonExpr) TypeCheck( return nil, err } + // REFCURSOR does not support comparisons. + leftType, rightType := leftTyped.ResolvedType(), rightTyped.ResolvedType() + if leftType.Family() == types.RefCursorFamily || rightType.Family() == types.RefCursorFamily { + return nil, pgerror.Newf(pgcode.UndefinedFunction, + "unsupported comparison operator: <%s> %s <%s>", leftType, cmpOp, rightType, + ) + } + if alwaysNull { return DNull, nil } @@ -1463,6 +1471,12 @@ func (expr *IsNullExpr) TypeCheck( if err != nil { return nil, err } + // REFCURSOR does not support comparisons. + if exprTyped.ResolvedType().Family() == types.RefCursorFamily { + return nil, pgerror.New(pgcode.UndefinedFunction, + "unsupported comparison operator: refcursor IS unknown", + ) + } expr.Expr = exprTyped expr.typ = types.Bool return expr, nil @@ -1476,6 +1490,12 @@ func (expr *IsNotNullExpr) TypeCheck( if err != nil { return nil, err } + // REFCURSOR does not support comparisons. + if exprTyped.ResolvedType().Family() == types.RefCursorFamily { + return nil, pgerror.New(pgcode.UndefinedFunction, + "unsupported comparison operator: refcursor IS NOT unknown", + ) + } expr.Expr = exprTyped expr.typ = types.Bool return expr, nil