-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
Add DATE and TIMESTAMP operators #9691
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
SET max_parser_depth = 4000; | ||
SELECT x FROM (SELECT number % 16 = 0 ? nan : (number % 24 = 0 ? NULL : (number % 37 = 0 ? nan : (number % 34 = 0 ? nan : (number % 3 = 0 ? NULL : (number % 68 = 0 ? 42 : (number % 28 = 0 ? nan : (number % 46 = 0 ? nan : (number % 13 = 0 ? nan : (number % 27 = 0 ? NULL : (number % 39 = 0 ? NULL : (number % 27 = 0 ? NULL : (number % 30 = 0 ? NULL : (number % 72 = 0 ? NULL : (number % 36 = 0 ? NULL : (number % 51 = 0 ? NULL : (number % 58 = 0 ? nan : (number % 26 = 0 ? 42 : (number % 13 = 0 ? nan : (number % 12 = 0 ? NULL : (number % 22 = 0 ? nan : (number % 36 = 0 ? NULL : (number % 63 = 0 ? NULL : (number % 27 = 0 ? NULL : (number % 18 = 0 ? NULL : (number % 69 = 0 ? NULL : (number % 76 = 0 ? nan : (number % 42 = 0 ? NULL : (number % 9 = 0 ? NULL : (toFloat64(number)))))))))))))))))))))))))))))) AS x FROM system.numbers LIMIT 1001) ORDER BY x ASC NULLS FIRST; | ||
|
||
SELECT x FROM (SELECT number % 22 = 0 ? nan : (number % 56 = 0 ? 42 : (number % 45 = 0 ? NULL : (number % 47 = 0 ? 42 : (number % 39 = 0 ? NULL : (number % 1 = 0 ? nan : (number % 43 = 0 ? nan : (number % 40 = 0 ? nan : (number % 42 = 0 ? NULL : (number % 26 = 0 ? 42 : (number % 41 = 0 ? 42 : (number % 6 = 0 ? NULL : (number % 39 = 0 ? NULL : (number % 34 = 0 ? nan : (number % 74 = 0 ? 42 : (number % 40 = 0 ? nan : (number % 37 = 0 ? nan : (number % 51 = 0 ? NULL : (number % 46 = 0 ? nan : (toFloat64(number)))))))))))))))))))) AS x FROM system.numbers LIMIT 1001) ORDER BY x ASC NULLS FIRST; | ||
SELECT x FROM (SELECT number % 22 = 0 ? nan : (number % 56 = 0 ? 42 : (number % 45 = 0 ? NULL : (number % 47 = 0 ? 42 : (number % 39 = 0 ? NULL : (number % 1 = 0 ? nan : (number % 43 = 0 ? nan : (number % 40 = 0 ? nan : (number % 42 = 0 ? NULL : (number % 26 = 0 ? 42 : (number % 41 = 0 ? 42 : (number % 6 = 0 ? NULL : (number % 39 = 0 ? NULL : (number % 34 = 0 ? nan : (number % 74 = 0 ? 42 : (number % 40 = 0 ? nan : (number % 37 = 0 ? nan : (number % 51 = 0 ? NULL : (number % 46 = 0 ? nan : (toFloat64(number)))))))))))))))))))) AS x FROM system.numbers LIMIT 1001) ORDER BY x ASC NULLS FIRST; |
2 changes: 1 addition & 1 deletion
2
dbms/tests/queries/0_stateless/01062_max_parser_depth.reference
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
- | ||
Maximum parse depth (40) exceeded. | ||
Maximum parse depth (42) exceeded. | ||
- | ||
Maximum parse depth (20) exceeded. |
This file contains 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 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
14 changes: 14 additions & 0 deletions
14
dbms/tests/queries/0_stateless/01099_operators_date_and_timestamp.reference
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
1 1 1 | ||
1 1 1 | ||
1 1 | ||
2001-09-28 | ||
2001-10-05 Date | ||
2001-09-24 Date | ||
2001-10-05 Date | ||
2001-09-24 Date | ||
2001-09-28 01:00:00 DateTime | ||
2001-09-27 23:00:00 DateTime | ||
3 Int32 | ||
2001-09-29 00:00:00 | ||
2001-09-28 00:00:00 | ||
140400 Int32 |
31 changes: 31 additions & 0 deletions
31
dbms/tests/queries/0_stateless/01099_operators_date_and_timestamp.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
select interval 1 second, interval 1 minute, interval 1 hour; | ||
select interval 1 day, interval 1 week, interval 1 month; | ||
select interval 1 quarter, interval 1 year; | ||
|
||
select date '2001-09-28'; | ||
select (date '2001-09-28' + interval 7 day) x, toTypeName(x); | ||
select (date '2001-10-01' - interval 7 day) x, toTypeName(x); | ||
select (date '2001-09-28' + 7) x, toTypeName(x); | ||
select (date '2001-10-01' - 7) x, toTypeName(x); | ||
select (date '2001-09-28' + interval 1 hour) x, toTypeName(x); | ||
select (date '2001-09-28' - interval 1 hour) x, toTypeName(x); | ||
select (date '2001-10-01' - date '2001-09-28') x, toTypeName(x); | ||
select timestamp '2001-09-28 01:00:00' + interval 23 hour; | ||
select timestamp '2001-09-28 23:00:00' - interval 23 hour; | ||
|
||
-- TODO: return interval | ||
select (timestamp '2001-09-29 03:00:00' - timestamp '2001-09-27 12:00:00') x, toTypeName(x); -- interval '1 day 15:00:00' | ||
|
||
-- select -interval 23 hour; -- interval '-23:00:00' | ||
-- select interval 1 day + interval 1 hour; -- interval '1 day 01:00:00' | ||
-- select interval '1 day' - interval '1 hour'; -- interval '1 day -01:00:00' | ||
|
||
-- select date '2001-09-28' + time '03:00'; -- timestamp '2001-09-28 03:00:00' | ||
-- select time '01:00' + interval '3 hours'; -- time '04:00:00' | ||
-- select time '05:00' - time '03:00'; -- interval '02:00:00' | ||
-- select time '05:00' - interval '2 hours'; -- time '03:00:00' | ||
|
||
-- select 900 * interval '1 second'; -- interval '00:15:00' | ||
-- select (21 * interval '1 day') x, toTypeName(x); -- interval '21 days' | ||
-- select (double precision '3.5' * interval '1 hour') x, toTypeName(x); -- interval '03:30:00' | ||
-- select (interval '1 hour' / double precision '1.5') x, toTypeName(x); -- interval '00:40:00' |
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.
But why it's just for literals?
Does SQL standard support
DATE x
?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.
It sayes this:
I haven't found any place where it would be applyed to non literal. In MySQL it's also possible to apply DATE operator for timestamp string to exptract date. In PG it's possible to cropp seconds in timestamp string. But for SQL compatibility we need TIME, 6-digits afrer dot TIMESTAMP and lots of copmarison, timezones and operation results rules.