MCPcopy Create free account
hub / github.com/dolthub/doltgresql / typeCheckTupleComparison

Function typeCheckTupleComparison

postgres/parser/sem/tree/type_check.go:2233–2258  ·  view source on GitHub ↗

typeCheckTupleComparison type checks a comparison between two tuples, asserting that the elements of the two tuples are comparable at each index.

(
	ctx context.Context, semaCtx *SemaContext, op ComparisonOperator, left *Tuple, right *Tuple,
)

Source from the content-addressed store, hash-verified

2231// typeCheckTupleComparison type checks a comparison between two tuples,
2232// asserting that the elements of the two tuples are comparable at each index.
2233func typeCheckTupleComparison(
2234 ctx context.Context, semaCtx *SemaContext, op ComparisonOperator, left *Tuple, right *Tuple,
2235) (TypedExpr, TypedExpr, error) {
2236 // All tuples must have the same length.
2237 tupLen := len(left.Exprs)
2238 if err := checkTupleHasLength(right, tupLen); err != nil {
2239 return nil, nil, err
2240 }
2241 left.typ = types.MakeTuple(make([]*types.T, tupLen))
2242 right.typ = types.MakeTuple(make([]*types.T, tupLen))
2243 for elemIdx := range left.Exprs {
2244 leftSubExpr := left.Exprs[elemIdx]
2245 rightSubExpr := right.Exprs[elemIdx]
2246 leftSubExprTyped, rightSubExprTyped, _, _, err := typeCheckComparisonOp(ctx, semaCtx, op, leftSubExpr, rightSubExpr)
2247 if err != nil {
2248 exps := Exprs([]Expr{left, right})
2249 return nil, nil, pgerror.Newf(pgcode.DatatypeMismatch, "tuples %s are not comparable at index %d: %s",
2250 &exps, elemIdx+1, err)
2251 }
2252 left.Exprs[elemIdx] = leftSubExprTyped
2253 left.typ.TupleContents()[elemIdx] = leftSubExprTyped.ResolvedType()
2254 right.Exprs[elemIdx] = rightSubExprTyped
2255 right.typ.TupleContents()[elemIdx] = rightSubExprTyped.ResolvedType()
2256 }
2257 return left, right, nil
2258}
2259
2260// typeCheckSameTypedTupleExprs type checks a list of expressions, asserting
2261// that all are tuples which have the same type or nulls. The function expects

Callers 1

typeCheckComparisonOpFunction · 0.85

Calls 7

MakeTupleFunction · 0.92
NewfFunction · 0.92
checkTupleHasLengthFunction · 0.85
typeCheckComparisonOpFunction · 0.85
ExprsTypeAlias · 0.85
TupleContentsMethod · 0.80
ResolvedTypeMethod · 0.65

Tested by

no test coverage detected