From b080b70d8c357d03a8b87f724d481bdbc1e27d2f Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 5 Jun 2018 10:53:32 +0200 Subject: [PATCH] sql: properly mark current_date as impure Release note (bug fix): Fixed a bug where a long-running query running from one day to the next would not always produce the right value for `current_date()`. --- pkg/sql/sem/builtins/builtins.go | 1 + pkg/sql/sem/tree/normalize_test.go | 1 + 2 files changed, 2 insertions(+) diff --git a/pkg/sql/sem/builtins/builtins.go b/pkg/sql/sem/builtins/builtins.go index 430b227ae380..7d2cc1453afe 100644 --- a/pkg/sql/sem/builtins/builtins.go +++ b/pkg/sql/sem/builtins/builtins.go @@ -1268,6 +1268,7 @@ CockroachDB supports the following flags: "current_date": { tree.Builtin{ + Impure: true, Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.Date), Fn: func(ctx *tree.EvalContext, args tree.Datums) (tree.Datum, error) { diff --git a/pkg/sql/sem/tree/normalize_test.go b/pkg/sql/sem/tree/normalize_test.go index 9b9afc6af156..00e5380041ce 100644 --- a/pkg/sql/sem/tree/normalize_test.go +++ b/pkg/sql/sem/tree/normalize_test.go @@ -144,6 +144,7 @@ func TestNormalizeExpr(t *testing.T) { {`s=lower('FOO')`, `s = 'foo'`}, {`lower(s)='foo'`, `lower(s) = 'foo'`}, {`random()`, `random()`}, + {`current_date()`, `current_date()`}, {`a=count('FOO') OVER ()`, `a = count('FOO') OVER ()`}, {`9223372036854775808`, `9223372036854775808`}, {`-9223372036854775808`, `-9223372036854775808`},