-
Notifications
You must be signed in to change notification settings - Fork 14
Add page for timestamp #416
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
Open
WanYixian
wants to merge
3
commits into
main
Choose a base branch
from
wyx/add-timestamp-dedicated-page
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| --- | ||
| title: "Timestamp" | ||
| sidebarTitle: Timestamp type | ||
| description: "Use the timestamp data type to handle date and time information." | ||
| --- | ||
|
|
||
| Timestamp data types are used to store and process precise time information. RisingWave supports two types of timestamps: | ||
|
|
||
| - `timestamp`: Stores date and time values without timezone, supporting up to **nanosecond** precision (9 digits after the decimal point). | ||
|
|
||
| - `timestamptz`: Stores date and time values along with time zone information, supporting up to **microsecond** precision (6 digits after the decimal point). | ||
|
|
||
|
|
||
| ## Precision preservation | ||
|
|
||
| <Note> | ||
| Added in version 2.1. | ||
| </Note> | ||
|
|
||
| Nanosecond precision is fully maintained for `timestamp` during the following operations: | ||
|
|
||
| - Reading from or writing to external sources (Kafka, Iceberg, Parquet, etc.) preserves nanoseconds automatically. | ||
|
|
||
| - Adding or subtracting an interval from a timestamp. | ||
|
|
||
| ```sql Add an interval | ||
| SELECT '2022-03-13 01:00:00.123456789'::timestamp + INTERVAL '24' HOUR; | ||
| -- Result: 2022-03-14 01:00:00.123456789 | ||
| ``` | ||
|
|
||
| ```sql Subtract an interval | ||
| SELECT '2022-03-14 01:00:00.123456789'::timestamp - INTERVAL '24' HOUR; | ||
| -- Result: 2022-03-13 01:00:00.123456789 | ||
| ``` | ||
|
|
||
| ## Precision loss | ||
|
|
||
| Nanosecond precision is lost (truncated to microseconds or discarded) under the following scenarios: | ||
|
|
||
| - Converting timestamp to types with lower precision: | ||
| - timestamptz | ||
| - time | ||
| - date | ||
|
|
||
| - Subtracting Timestamps (timestamp - timestamp): The result is an interval, which only has microsecond precision. | ||
| ```sql Subtract two timestamps | ||
| SELECT '2022-03-13 03:00:00.123456789'::timestamp - '2022-03-13 01:00:00.000000000'::timestamp; | ||
| -- Result: 02:00:00.123456 (Note that nanosecond precision is truncated.) | ||
| ``` | ||
|
|
||
| ## Related topic | ||
|
|
||
| For more functions and usage on timestamp, see [Date and time functions and operators](/sql/functions/datetime). | ||
|
|
||
|
|
||
|
|
||
Oops, something went wrong.
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.
https://www.notion.so/Working-with-Nanosecond-Precision-Timestamps-in-RisingWave-draft-1e2f0d69cb7680dbafa1ec51842354ad?d=1e3f0d69cb7680e08b7f001c1ee500ef&pvs=4#1e3f0d69cb7680b8a436ee5287f0ed27
The nano precision in v2.1 is problematic and will be REVERTED for a better alternative (without the precision loss issue below). Let's refrain from publishing it.
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.
Thanks! So shall we just mark it as v2.2, or wait until the fix is ready to publish?
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.
The proper nano precision support is not even being worked on in v2.5. So the "promotion" of nano support shall be put on hold until it is ready.
If we are going to have a dedicated page for time related data types, it is better focus on the difference between timestamp and timestamptz, and when to use which (short answer: always prefer timestamptz unless you stick to a single offset)