-
Notifications
You must be signed in to change notification settings - Fork 615
Support CREATE TABLE ON UPDATE <expr>
Function
#685
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it take an expression?
ON UPDATE CURRENT TIMESTAMP
is an expression by itself (1). You can takeTIMESTAMP [(p)]
for the parameter, as long as I'm aware of it.There's no reason to make it complex to the upstream with expressions, as there's no
ON UPDATE column_1
, for example.You could make it
OnUpdateCurrentTimestamp(Option<u64>)
to get the precision, maybe?I don't think there are things like
ON UPDATE CURRENT TIMESTAMP WITH TIMEZONE
exist at all, so only having the precision should be enough.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this with mysql and the syntax is accepted
Which is very strange to me as the documentation doesn't seem to allow that syntax 🤔
https://dev.mysql.com/doc/refman/8.0/en/create-table.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alamb this is a specific syntax from MySQL (1)
The problem is, the documentation states that the
ON UPDATE CURRENT_TIMESTAMP
is a special expression uniquely. The only possible modification seems to be the precision informationON UPDATE CURRENT_TIMESTAMP(n)
, which is dependant on the data type for that column.But this PR seems to expect any expression, which doesn't make sense, and it makes the upstream handle all other possible expressions as errors, which we should do.
[1] : https://dev.mysql.com/doc/refman/8.0/en/timestamp-initialization.html
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand "expression" issue you are raising.
OnUpdateCurrentTimestamp(Option<u64>)
is also good proposal which I was thinking about it. But I am confused in "CurrentTimestamp".In this document, CurrentTimestamp belongs to Function and MySQL make it as special expression without using parentheses. In MySQL, it seems to get ON UPDATE . Maybe it would be good to make reservation expression function options which has no parentheses and make users write both CURRENT_TIMESTAMP and CURRENTP_TIMESTAMP()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CEOJINSUNG I kinda agree, but the function and the expression are not the same.
Either way, maybe you can have an enum there?
Like
Other approach would be something like:
Where the internal option is the precision, and the external the presence of parenthesis. But seems less idiomatic and a little obscure for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AugustoFKL Thanks for the suggestion But in sqlparse-rs structure, Function belongs to Expr. And I think it is not good structure because there is no scalability. OnUpdateCurrentTimestampInfo looks like only using for MySQL.
There are another functions without parenthesis like DIV, SYSDATE Function.
An extensible structure that can be freely added to functions used without parentheses such as DIV and SYSDATE is required like below NoArgsFunction.
Since SQL is used in various places such as MySQL, Oracle, PosgreSQL, etc., OnupdateCurrentTimeStamp does not seem to be a very good structure even for the open-close principle. Therefore, I think it would be better to respond so that elements used without parentheses can be freely added to functions without arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CEOJINSUNG but can you say that this is a function per se?
To me it looks like a really special case.