Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
38 changes: 38 additions & 0 deletions docs/reference/sql/data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,44 @@ Supported abbreviations include:
| us | microseconds |
| ns | nanoseconds |

#### INTERVAL keyword

In the examples above, we used the cast operation `'{quantity unit}'::INTERVAL` to demonstrate the interval type. In fact, the interval type can also be used with the syntax supported by the `INTERVAL` keyword, though the behavior varies between database dialects:

1. In MySQL, the syntax is `INTERVAL {quantity} {unit}`, where `quantity` can be a number or a string depending on the context. For example:
```sql
mysql> SELECT INTERVAL 1 YEAR;
+--------------------------------------------------------------------------------------+
| IntervalMonthDayNano("IntervalMonthDayNano { months: 12, days: 0, nanoseconds: 0 }") |
+--------------------------------------------------------------------------------------+
| P1Y0M0DT0H0M0S |
+--------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

mysql> SELECT INTERVAL '1 YEAR 2' MONTH;
+--------------------------------------------------------------------------------------+
| IntervalMonthDayNano("IntervalMonthDayNano { months: 14, days: 0, nanoseconds: 0 }") |
+--------------------------------------------------------------------------------------+
| P1Y2M0DT0H0M0S |
+--------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```

2. In PostgreSQL and the default GreptimeDB dialect, it is `INTERVAL '{quantity unit}'`, where the INTERVAL keyword is followed by the interval string:
```sql
public=> SELECT INTERVAL '1 year';
IntervalMonthDayNano("IntervalMonthDayNano { months: 12, days: 0, nanoseconds: 0 }")
--------------------------------------------------------------------------------------
1 year
(1 row)

public=> SELECT INTERVAL '1 year 2 month';
IntervalMonthDayNano("IntervalMonthDayNano { months: 14, days: 0, nanoseconds: 0 }")
--------------------------------------------------------------------------------------
1 year 2 mons
(1 row)
```

## JSON Type (Experimental)

:::warning
Expand Down
4 changes: 4 additions & 0 deletions docs/user-guide/timezone.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ To configure the time zone for the PostgreSQL client, please refer to the [time

When using the HTTP API, you can specify the time zone through the header parameter. For more information, please refer to the [HTTP API documentation](/user-guide/protocols/http.md#time-zone).

### Dashboard

The dashboard will use the local timezone as the default timezone value. You can change it in the settings menu.

### Other clients

For other clients, you can change [the default time zone configuration](/user-guide/deployments-administration/configuration.md#default-time-zone-configuration) of GreptimeDB.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,44 @@ SELECT '-1h5m'::INTERVAL;
| us | microseconds |
| ns | nanoseconds |

#### INTERVAL 关键字

在上述示例中,我们使用了 `cast` 类型转换操作 `'{quantity unit}'::INTERVAL` 来演示 interval 类型。实际上,interval 类型也可以使用 `INTERVAL` 关键字支持的语法,不过不同数据库方言之间的行为有所差异:

1. 在 MySQL 中,语法为 `INTERVAL {quantity} {unit}`,其中 `quantity` 可以是数字或字符串,具体取决于上下文。例如:
```sql
mysql> SELECT INTERVAL 1 YEAR;
+--------------------------------------------------------------------------------------+
| IntervalMonthDayNano("IntervalMonthDayNano { months: 12, days: 0, nanoseconds: 0 }") |
+--------------------------------------------------------------------------------------+
| P1Y0M0DT0H0M0S |
+--------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

mysql> SELECT INTERVAL '1 YEAR 2' MONTH;
+--------------------------------------------------------------------------------------+
| IntervalMonthDayNano("IntervalMonthDayNano { months: 14, days: 0, nanoseconds: 0 }") |
+--------------------------------------------------------------------------------------+
| P1Y2M0DT0H0M0S |
+--------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```

2. 在 PostgreSQL 和默认的 GreptimeDB 方言中,语法为 `INTERVAL '{quantity unit}'`,即 INTERVAL 关键字后跟 interval 字符串:
```sql
public=> SELECT INTERVAL '1 year';
IntervalMonthDayNano("IntervalMonthDayNano { months: 12, days: 0, nanoseconds: 0 }")
--------------------------------------------------------------------------------------
1 year
(1 row)

public=> SELECT INTERVAL '1 year 2 month';
IntervalMonthDayNano("IntervalMonthDayNano { months: 14, days: 0, nanoseconds: 0 }")
--------------------------------------------------------------------------------------
1 year 2 mons
(1 row)
```

## JSON 类型(实验功能)

:::warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ GreptimeDB 在数据写入或查询时,会根据指定的时区将时间值从

使用 HTTP API 时,你可以通过 header 参数指定时区。有关更多信息,请参阅 [HTTP API 文档](/user-guide/protocols/http.md#时区)。

### Dashboard

Dashboard 将使用本地时区作为默认时区值。您可以在 settings 菜单中更改它。

### 其他客户端

对于其他客户端,你可以更改 GreptimeDB 的[默认时区配置](/user-guide/deployments-administration/configuration.md#默认时区配置)。
Expand Down
Loading