// SanitizeDefaultExpr verifies a default expression is valid and has the // correct type. func SanitizeDefaultExpr(expr parser.Expr, colDatumType parser.Datum) error { typedExpr, err := parser.TypeCheck(expr, nil, colDatumType) if err != nil { return err } if defaultType := typedExpr.ReturnType(); !colDatumType.TypeEqual(defaultType) { return incompatibleColumnDefaultTypeError(colDatumType, defaultType) } if parser.ContainsVars(typedExpr) { return defaultContainsPlaceholdersError(typedExpr) } return nil }
// SanitizeVarFreeExpr verifies a default expression is valid, has the // correct type and contains no variable expressions. func SanitizeVarFreeExpr(expr parser.Expr, expectedType parser.Datum, context string) error { if parser.ContainsVars(expr) { return exprContainsVarsError(context, expr) } typedExpr, err := parser.TypeCheck(expr, nil, expectedType) if err != nil { return err } if defaultType := typedExpr.ReturnType(); !expectedType.TypeEqual(defaultType) { return incompatibleExprTypeError(context, expectedType, defaultType) } return nil }