Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support DATE, TIME, and TIMESTAMP literal parsing #346

Merged
merged 3 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -5448,6 +5448,10 @@ func NewBitVal(in []byte) *SQLVal {
return &SQLVal{Type: BitVal, Val: in}
}

// TODO: implement a NewDateVal()
// TODO: implement a NewTimeVal()
// TODO: implement a NewTimestampVal()

// NewValArg builds a new ValArg.
func NewValArg(in []byte) *SQLVal {
return &SQLVal{Type: ValArg, Val: in}
Expand Down
59 changes: 59 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4022,6 +4022,55 @@ var (
"\ti int\n" +
") insert_method last",
},

// Date, Time, and Timestamp literals
{
input: "select date '2020-10-01'",
output: "select '2020-10-01'",
},
{
input: "select time '2020-10-01'",
output: "select '2020-10-01'",
},
{
input: "select timestamp '2020-10-01'",
output: "select '2020-10-01'",
},

{
input: "select date'2020-10-01'",
output: "select '2020-10-01'",
},
{
input: "select time'2020-10-01'",
output: "select '2020-10-01'",
},
{
input: "select timestamp'2020-10-01'",
output: "select '2020-10-01'",
},

{
input: "select (date '2020-10-01')",
output: "select ('2020-10-01')",
},
{
input: "select (time '2020-10-01')",
output: "select ('2020-10-01')",
},
{
input: "select (timestamp '2020-10-01')",
output: "select ('2020-10-01')",
},

{
input: "insert into t values (date '2020-10-01'), (time '2020-10-01'), (timestamp '2020-10-01')",
output: "insert into t values ('2020-10-01'), ('2020-10-01'), ('2020-10-01')",
},
{
input: "select * from (values row(date '2020-10-01', time '12:34:56', timestamp '2001-02-03 12:34:56')) t;",
output: "select * from (values row('2020-10-01', '12:34:56', '2001-02-03 12:34:56')) as t",
},
}

// Any tests that contain multiple statements within the body (such as BEGIN/END blocks) should go here.
Expand Down Expand Up @@ -5012,6 +5061,7 @@ func TestInvalid(t *testing.T) {
invalidSQL := []struct {
input string
err string
skip bool
}{
{
input: "SET @foo = `o` `ne`;",
Expand Down Expand Up @@ -5183,6 +5233,15 @@ func TestInvalid(t *testing.T) {
input: "select * from tbl into outfile 'outfile.txt' lines starting by 'd' terminated by 'e' starting by 'd' terminated by 'e'",
err: "syntax error",
},

{
input: "select date 20010203",
err: "syntax error",
},
{
input: "select date concat('2001-', '02-', '03')",
err: "syntax error",
},
}

for _, tcase := range invalidSQL {
Expand Down
Loading