( ctx context.Context, semaCtx *SemaContext, op ComparisonOperator, left, right Expr, )
| 1831 | } |
| 1832 | |
| 1833 | func typeCheckComparisonOp( |
| 1834 | ctx context.Context, semaCtx *SemaContext, op ComparisonOperator, left, right Expr, |
| 1835 | ) (_ TypedExpr, _ TypedExpr, _ *CmpOp, alwaysNull bool, _ error) { |
| 1836 | foldedOp, foldedLeft, foldedRight, switched, _ := FoldComparisonExpr(op, left, right) |
| 1837 | ops := CmpOps[foldedOp] |
| 1838 | |
| 1839 | _, leftIsTuple := foldedLeft.(*Tuple) |
| 1840 | rightTuple, rightIsTuple := foldedRight.(*Tuple) |
| 1841 | |
| 1842 | _, rightIsSubquery := foldedRight.(SubqueryExpr) |
| 1843 | switch { |
| 1844 | case foldedOp == In && rightIsTuple: |
| 1845 | sameTypeExprs := make([]Expr, len(rightTuple.Exprs)+1) |
| 1846 | sameTypeExprs[0] = foldedLeft |
| 1847 | copy(sameTypeExprs[1:], rightTuple.Exprs) |
| 1848 | |
| 1849 | typedSubExprs, retType, err := TypeCheckSameTypedExprs(ctx, semaCtx, types.Any, sameTypeExprs...) |
| 1850 | if err != nil { |
| 1851 | sigWithErr := fmt.Sprintf(compExprsFmt, left, op, right, err) |
| 1852 | return nil, nil, nil, false, |
| 1853 | pgerror.Newf(pgcode.InvalidParameterValue, unsupportedCompErrFmt, sigWithErr) |
| 1854 | } |
| 1855 | |
| 1856 | fn, ok := ops.LookupImpl(retType, types.AnyTuple) |
| 1857 | if !ok { |
| 1858 | sig := fmt.Sprintf(compSignatureFmt, retType, op, types.AnyTuple) |
| 1859 | return nil, nil, nil, false, |
| 1860 | pgerror.Newf(pgcode.InvalidParameterValue, unsupportedCompErrFmt, sig) |
| 1861 | } |
| 1862 | |
| 1863 | typedLeft := typedSubExprs[0] |
| 1864 | typedSubExprs = typedSubExprs[1:] |
| 1865 | |
| 1866 | rightTuple.typ = types.MakeTuple(make([]*types.T, len(typedSubExprs))) |
| 1867 | for i, typedExpr := range typedSubExprs { |
| 1868 | rightTuple.Exprs[i] = typedExpr |
| 1869 | rightTuple.typ.TupleContents()[i] = retType |
| 1870 | } |
| 1871 | if switched { |
| 1872 | return rightTuple, typedLeft, fn, false, nil |
| 1873 | } |
| 1874 | return typedLeft, rightTuple, fn, false, nil |
| 1875 | |
| 1876 | case foldedOp == In && rightIsSubquery: |
| 1877 | typedLeft, err := foldedLeft.TypeCheck(ctx, semaCtx, types.Any) |
| 1878 | if err != nil { |
| 1879 | sigWithErr := fmt.Sprintf(compExprsFmt, left, op, right, err) |
| 1880 | return nil, nil, nil, false, |
| 1881 | pgerror.Newf(pgcode.InvalidParameterValue, unsupportedCompErrFmt, sigWithErr) |
| 1882 | } |
| 1883 | |
| 1884 | typ := typedLeft.ResolvedType() |
| 1885 | fn, ok := ops.LookupImpl(typ, types.AnyTuple) |
| 1886 | if !ok { |
| 1887 | sig := fmt.Sprintf(compSignatureFmt, typ, op, types.AnyTuple) |
| 1888 | return nil, nil, nil, false, |
| 1889 | pgerror.Newf(pgcode.InvalidParameterValue, unsupportedCompErrFmt, sig) |
| 1890 | } |
no test coverage detected