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

MySQL - On Update not taking expression #543

Open
Sibz opened this issue Jul 16, 2022 · 5 comments
Open

MySQL - On Update not taking expression #543

Sibz opened this issue Jul 16, 2022 · 5 comments

Comments

@Sibz
Copy link

Sibz commented Jul 16, 2022

CREATE TABLE foo (`modification_time` DATETIME ON UPDATE CURRENT_TIMESTAMP())

does not work

Sibz added a commit to rustanigans/sqlparser-rs that referenced this issue Jul 16, 2022
@Sibz
Copy link
Author

Sibz commented Jul 16, 2022

I am trying to resolve this
rustanigans@2585a03

But unable to work out how to make the test:
https://github.com/rustanigans/sqlparser-rs/blob/2585a03b6d7e700e0fe619e53e641af05c86bf9a/tests/sqlparser_mysql.rs#L853-L875
Not sure on how to assert against an expr

Also the ColumnOption::DialectSpecific only takes vec of tokens, so I had to add one for this that takes an expr:
https://github.com/rustanigans/sqlparser-rs/blob/2585a03b6d7e700e0fe619e53e641af05c86bf9a/src/ast/ddl.rs#L378-L379

If anyone could provide a bit of guidance I will make a PR once resolved.

@alamb
Copy link
Contributor

alamb commented Jul 28, 2022

I think if you make a PR that is likely the best way to get guidance.

Sibz added a commit to rustanigans/sqlparser-rs that referenced this issue Aug 19, 2022
@AugustoFKL
Copy link
Contributor

AugustoFKL commented Oct 1, 2022

@Sibz looking at MySQL's CREATE TABLE doc (1), I couldn't find why you're trying to give it an expression, as MySQL seems to follow the standard when it comes to the ON UPDATE clause(2).

You're trying to add the ON UPDATE CURRENT_TIMESTAMP clause (3), which is a unique kind of parameter.

[1] : https://dev.mysql.com/doc/refman/8.0/en/create-table.html
[2] : https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#update-rule
[3]: https://dev.mysql.com/doc/refman/8.0/en/timestamp-initialization.html

@Sibz
Copy link
Author

Sibz commented Oct 6, 2022

Yes your right, it doesn't take an expression per se, only takes CURRENT_TIMESTAMP or NOW but something must be provided, currently it's broken as will not parse those key words.

@Sibz
Copy link
Author

Sibz commented Oct 7, 2022

And further, we must support all synonyms of CURRENT_TIMESTAMP:
CURRENT_TIMESTAMP(), NOW(), LOCALTIME, LOCALTIME(), LOCALTIMESTAMP and LOCALTIMESTAMP()
Parse considers the ones without parenthesis keywords but the ones with as expressions.

I will review my code and test as soon as I have chance, though I am very busy these days.

Sibz added a commit to rustanigans/sqlparser-rs that referenced this issue Dec 19, 2022
Sibz added a commit to rustanigans/sqlparser-rs that referenced this issue Dec 19, 2022
Sibz added a commit to rustanigans/sqlparser-rs that referenced this issue Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants