Skip to content
Open
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
1 change: 1 addition & 0 deletions mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@
"sql/data-types/map-type",
"sql/data-types/jsonb",
"sql/data-types/rw-int256",
"sql/data-types/timestamp",
"sql/data-types/supported-protobuf-types"
]
},
Expand Down
56 changes: 56 additions & 0 deletions sql/data-types/timestamp.mdx
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.
Copy link
Contributor

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.

Copy link
Collaborator Author

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?

Copy link
Contributor

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)

</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).



Loading