diff --git a/pkg/sql/plan2/build_function.go b/pkg/sql/plan2/build_function.go index e90c70f185feb00ff4dcc72f276a1a88d82db1b5..c3beb7a19a2afe24e88de397e859b9ffbafb231f 100644 --- a/pkg/sql/plan2/build_function.go +++ b/pkg/sql/plan2/build_function.go @@ -171,6 +171,14 @@ func getFunctionExprByNameAndAstExprs(name string, astExprs []tree.Expr, ctx Com if len(args) != 2 { return nil, false, errors.New(errno.SyntaxErrororAccessRuleViolation, "date_add/date_sub function need two args") } + if args[0].Typ.Id == plan.Type_VARCHAR { + args[0], err = appendCastExpr(args[0], &plan.Type{ + Id: plan.Type_DATE, + }) + if err != nil { + return + } + } args, err = resetIntervalFunctionExprs(args[0], args[1]) if err != nil { return diff --git a/pkg/sql/plan2/build_test.go b/pkg/sql/plan2/build_test.go index 326884f5e06ff6cb117c5b670d473be93fdf9cbf..6e0d20a5ecd16b310e70b5df58743aa78dfcc473 100644 --- a/pkg/sql/plan2/build_test.go +++ b/pkg/sql/plan2/build_test.go @@ -403,6 +403,7 @@ func TestSingleTableSqlBuilder(t *testing.T) { "select sum(n_nationkey) as s from nation order by s", "select date_add(date '2001-01-01', interval 1 day) as a", "select date_sub(date '2001-01-01', interval '1 day') as a", + "select date_add('2001-01-01', interval '1 day') as a", "SELECT N_REGIONKEY + 2 as a, N_REGIONKEY/2, N_REGIONKEY* N_NATIONKEY, N_REGIONKEY % N_NATIONKEY, N_REGIONKEY - N_NATIONKEY FROM NATION WHERE -N_NATIONKEY < -20", //test more expr "SELECT N_REGIONKEY FROM NATION where N_REGIONKEY >= N_NATIONKEY or (N_NAME like '%ddd' and N_REGIONKEY >0.5)", //test more expr