Skip to content

Commit e184e89

Browse files
committed
Create interval.md
1 parent d47e110 commit e184e89

File tree

1 file changed

+36
-0
lines changed
  • docs/en/sql-reference/00-sql-reference/10-data-types

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Interval
3+
---
4+
5+
import FunctionDescription from '@site/src/components/FunctionDescription';
6+
7+
<FunctionDescription description="Introduced or updated: v1.2.673"/>
8+
9+
The INTERVAL data type represents a duration of time, allowing precise manipulation and storage of time intervals across various units.
10+
11+
- Supports units including `Millennium`, `Century`, `Decade`, `Year`, `Quarter`, `Month`, `Week`, `Day`, `Hour`, `Minute`, `Second`, `Millisecond`, and `Microsecond`.
12+
- Accepts natural language formats (e.g., '1 year 2 months ago') or numeric values interpreted as microseconds.
13+
- Handles both positive and negative intervals with precision down to microseconds.
14+
- It is *not* recommended to use the MySQL client to query INTERVAL columns in Databend, as the MySQL protocol does not fully support the INTERVAL type. This may result in errors or unexpected behavior.
15+
16+
```sql title='Examples:'
17+
-- Create a table with one INTERVAL column
18+
CREATE OR REPLACE TABLE intervals (duration INTERVAL);
19+
20+
-- Insert different types of INTERVAL data
21+
INSERT INTO intervals VALUES
22+
('1 year 2 months ago'), -- Natural language format with 'ago' (negative interval)
23+
('1 year 2 months'), -- Natural language format without 'ago' (positive interval)
24+
('1000000'), -- Positive numeric value interpreted as microseconds
25+
('-1000000'); -- Negative numeric value interpreted as microseconds
26+
27+
-- Query the table to see the results
28+
SELECT * FROM intervals;
29+
30+
duration |
31+
------------------------+
32+
-1 year -2 months |
33+
1 year 2 months |
34+
0:00:01 |
35+
-1 month -1 day -0:00:01|
36+
```

0 commit comments

Comments
 (0)