You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/sql-reference/00-sql-reference/10-data-types/interval.md
+39-24Lines changed: 39 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,30 +8,45 @@ import FunctionDescription from '@site/src/components/FunctionDescription';
8
8
9
9
The INTERVAL data type represents a duration of time, allowing precise manipulation and storage of time intervals across various units.
10
10
11
-
- Supports units including `Millennium`, `Century`, `Decade`, `Year`, `Quarter`, `Month`, `Week`, `Day`, `Hour`, `Minute`, `Second`, `Millisecond`, and `Microsecond`.
12
11
- Accepts natural language formats (e.g., '1 year 2 months ago') or numeric values interpreted as microseconds.
12
+
13
+
- Supports time units including `Millennium`, `Century`, `Decade`, `Year`, `Quarter`, `Month`, `Week`, `Day`, `Hour`, `Minute`, `Second`, `Millisecond`, and `Microsecond`.
14
+
15
+
```sql title='Examples:'
16
+
-- Create a table with one INTERVAL column
17
+
CREATE OR REPLACETABLEintervals (duration INTERVAL);
18
+
19
+
-- Insert different types of INTERVAL data
20
+
INSERT INTO intervals VALUES
21
+
('1 year 2 months ago'), -- Natural language format with 'ago' (negative interval)
22
+
('1 year 2 months'), -- Natural language format without 'ago' (positive interval)
23
+
('1000000'), -- Positive numeric value interpreted as microseconds
24
+
('-1000000'); -- Negative numeric value interpreted as microseconds
25
+
26
+
-- Query the table to see the results
27
+
SELECT*FROM intervals;
28
+
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
+
└──────────────────────────┘
37
+
```
38
+
39
+
- When given a numeric value, Databend only recognizes the integer part of the value. For example, both `TO_INTERVAL('1 seconds')`and`TO_INTERVAL('1.6 seconds')` represent an interval of 1 second. The fractional part after the decimalpoint is ignored.
- Handles both positive and negative intervals with precision down to microseconds.
14
51
- INTERVAL columns are *not* supported in the ORDER BY clause.
15
-
- 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.
16
-
17
-
```sql title='Examples:'
18
-
-- Create a table with one INTERVAL column
19
-
CREATE OR REPLACETABLEintervals (duration INTERVAL);
20
-
21
-
-- Insert different types of INTERVAL data
22
-
INSERT INTO intervals VALUES
23
-
('1 year 2 months ago'), -- Natural language format with 'ago' (negative interval)
24
-
('1 year 2 months'), -- Natural language format without 'ago' (positive interval)
25
-
('1000000'), -- Positive numeric value interpreted as microseconds
26
-
('-1000000'); -- Negative numeric value interpreted as microseconds
27
-
28
-
-- Query the table to see the results
29
-
SELECT*FROM intervals;
30
-
31
-
duration |
32
-
------------------------+
33
-
-1 year -2 months |
34
-
1 year 2 months |
35
-
0:00:01 |
36
-
-1 month -1 day -0:00:01|
37
-
```
52
+
- 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.
- Undropping a database does not automatically restore ownership to the original role. After undropping, ownership must be manually granted to the previous role or another role. Until then, the database will be accessible only to the `account-admin` role.
- Undropping a table does not automatically restore ownership to the original role. After undropping, ownership must be manually granted to the previous role or another role. Until then, the table will be accessible only to the `account-admin` role.
0 commit comments