Skip to content

Commit d5b6cd2

Browse files
Copilotkillme2008
andauthored
docs: update numeric type aliases aligned with PostgreSQL and MySQL (#2231)
Signed-off-by: Dennis Zhuang <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: killme2008 <[email protected]> Co-authored-by: Dennis Zhuang <[email protected]>
1 parent 4ea4447 commit d5b6cd2

File tree

2 files changed

+74
-36
lines changed

2 files changed

+74
-36
lines changed

docs/reference/sql/data-types.md

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ The maximum capacities of `String` and `Binary` are determined by their encoding
3131
| `Float32` | 32-bit IEEE754 floating point values | 4 Bytes |
3232
| `Float64` | Double precision IEEE 754 floating point values | 8 Bytes |
3333

34+
:::tip NOTE
35+
The descriptions here refer to **GreptimeDB native type information**, which are measured in **bits**.
36+
However, when using **SQL**, follow the conventions of **PostgreSQL** and **MySQL**, where types like `INT2`, `INT4`, `INT8`, `FLOAT4` and `FLOAT8` are defined in **bytes**.
37+
For example, in an SQL statement, `INT8` actually corresponds to **BigInt** (8 bytes, 64 bits).
38+
:::
39+
3440
## Decimal Type
3541

3642
GreptimeDB supports the `decimal` type, a fixed-point type represented as `decimal(precision, scale)`, where `precision` is the total number of digits, and `scale` is the number of digits in the fractional part. For example, `123.45` has a precision of 5 and a scale of 2.
@@ -303,24 +309,38 @@ INSERT INTO bools(b) VALUES (TRUE), (FALSE);
303309

304310
For users migrating from MySQL or PostgreSQL to GreptimeDB, GreptimeDB supports the following alias types.
305311

306-
| Data Type | Alias Types |
307-
| ---------------------- | --------------------------------------------------------------- |
308-
| `String` | `Text`, `TinyText`, `MediumText`, `LongText`, `Varchar`, `Char` |
309-
| `Binary` | `Varbinary` |
310-
| `Int8` | `TinyInt` |
311-
| `Int16` | `SmallInt` |
312-
| `Int32` | `Int` |
313-
| `Int64` | `BigInt` |
314-
| `UInt8` | `UnsignedTinyInt` |
315-
| `UInt16` | `UnsignedSmallInt` |
316-
| `UInt32` | `UnsignedInt` |
317-
| `UInt64` | `UnsignedBigInt` |
318-
| `Float32` | `Float` |
319-
| `Float64` | `Double` |
320-
| `TimestampSecond` | `Timestamp_s`, `Timestamp_sec`, `Timestamp(0)` |
321-
| `TimestampMillisecond` | `Timestamp`, `Timestamp_ms`, `Timestamp(3)` |
322-
| `TimestampMicroSecond` | `Timestamp_us`, `Timestamp(6)` |
323-
| `TimestampNanosecond` | `Timestamp_ns`, `Timestamp(9)` |
312+
313+
| SQL Datatype Alias | Native Datatype |
314+
| --------------------------------------------------------------- | ---------------------- |
315+
| `Text`, `TinyText`, `MediumText`, `LongText`, `Varchar`, `Char` | `String` |
316+
| `Varbinary` | `Binary` |
317+
| `TinyInt` | `Int8` |
318+
| `SmallInt`, `Int2` | `Int16` |
319+
| `Int`, `Int4` | `Int32` |
320+
| `BigInt`, `Int8` | `Int64` |
321+
| `UnsignedTinyInt` | `UInt8` |
322+
| `UnsignedSmallInt` | `UInt16` |
323+
| `UnsignedInt` | `UInt32` |
324+
| `UnsignedBigInt` | `UInt64` |
325+
| `Float`, `Float4` | `Float32` |
326+
| `Double`, `Float8` | `Float64` |
327+
| `Timestamp_s`, `Timestamp_sec`, `Timestamp(0)` | `TimestampSecond` |
328+
| `Timestamp`, `Timestamp_ms`, `Timestamp(3)` | `TimestampMillisecond` |
329+
| `Timestamp_us`, `Timestamp(6)` | `TimestampMicroSecond` |
330+
| `Timestamp_ns`, `Timestamp(9)` | `TimestampNanosecond` |
331+
332+
:::warning Note
333+
The type aliases `Int2`, `Int4`, `Int8`, `Float4`, and `Float8` follow the PostgreSQL and MySQL convention where these identifiers refer to the number of **bytes** (not bits) in the type.
334+
335+
Specifically:
336+
- `Int2` = 2 bytes = `SmallInt` (16-bit)
337+
- `Int4` = 4 bytes = `Int` (32-bit)
338+
- `Int8` = 8 bytes = `BigInt` (64-bit)
339+
- `Float4` = 4 bytes = `Float` (32-bit)
340+
- `Float8` = 8 bytes = `Double` (64-bit)
341+
342+
Note: GreptimeDB's native type names (like `UInt8`, `Int32`, `Int64`) refer to the number of **bits**, while the SQL aliases `Int2`, `Int4`, and `Int8` refer to the number of **bytes** following PostgreSQL/MySQL conventions. For example, the native type `Int8` is an 8-**bit** integer (`TinyInt`, 1 byte), while the SQL alias `INT8` maps to an 8-**byte** integer (`BigInt`, 64-bit).
343+
:::
324344

325345
You can use these alias types when creating tables.
326346
For example, use `Varchar` instead of `String`, `Double` instead of `Float64`, and `Timestamp(0)` instead of `TimestampSecond`.

i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/data-types.md

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ SQL 数据类型定义了列可以存储的数据类型。当您运行 `DESC TAB
3131
| `Float32` | 32 位 IEEE 754 浮点数 | 4 字节 |
3232
| `Float64` | 双精度 IEEE 754 浮点数 | 8 字节 |
3333

34+
:::tip 注意
35+
这里的描述指的是 GreptimeDB 原生类型信息,这些类型都是以 位(bits) 为单位的。但是,在使用 SQL 时,请遵循 PostgreSQL 和 MySQL 的惯例,其中 `INT2``INT4``INT8``FLOAT4``FLOAT8` 等类型都是以 字节(bytes) 为单位定义的。
36+
例如,在 SQL 语句中,`INT8` 实际上对应 `BigInt`(8 个字节,64 位)。
37+
:::
38+
3439
## Decimal 类型
3540

3641
GreptimeDB 支持 `decimal` 类型,这是一种定点类型,表示为 `decimal(precision, scale)`,其中 `precision` 是总位数,`scale` 是小数部分的位数。例如,`123.45` 的总位数为 5,小数位数为 2。
@@ -303,24 +308,37 @@ INSERT INTO bools(b) VALUES (TRUE), (FALSE);
303308

304309
对于从 MySQL 或 PostgreSQL 迁移到 GreptimeDB 的用户,GreptimeDB 支持以下类型别名。
305310

306-
| 数据类型 | 别名 |
307-
| ---------------------- | --------------------------------------------------------------- |
308-
| `String` | `Text`, `TinyText`, `MediumText`, `LongText`, `Varchar`, `Char` |
309-
| `Binary` | `Varbinary` |
310-
| `Int8` | `TinyInt` |
311-
| `Int16` | `SmallInt` |
312-
| `Int32` | `Int` |
313-
| `Int64` | `BigInt` |
314-
| `UInt8` | `UnsignedTinyInt` |
315-
| `UInt16` | `UnsignedSmallInt` |
316-
| `UInt32` | `UnsignedInt` |
317-
| `UInt64` | `UnsignedBigInt` |
318-
| `Float32` | `Float` |
319-
| `Float64` | `Double` |
320-
| `TimestampSecond` | `Timestamp_s`, `Timestamp_sec`, `Timestamp(0)` |
321-
| `TimestampMillisecond` | `Timestamp`, `Timestamp_ms` , `Timestamp(3)` |
322-
| `TimestampMicroSecond` | `Timestamp_us`, `Timestamp(6)` |
323-
| `TimestampNanosecond` | `Timestamp_ns`, `Timestamp(9)` |
311+
| SQL 类型别名 | Native 数据类型 |
312+
| --------------------------------------------------------------- | ---------------------- |
313+
| `Text`, `TinyText`, `MediumText`, `LongText`, `Varchar`, `Char` | `String` |
314+
| `Varbinary` | `Binary` |
315+
| `TinyInt` | `Int8` |
316+
| `SmallInt`, `Int2` | `Int16` |
317+
| `Int`, `Int4` | `Int32` |
318+
| `BigInt`, `Int8` | `Int64` |
319+
| `UnsignedTinyInt` | `UInt8` |
320+
| `UnsignedSmallInt` | `UInt16` |
321+
| `UnsignedInt` | `UInt32` |
322+
| `UnsignedBigInt` | `UInt64` |
323+
| `Float`, `Float4` | `Float32` |
324+
| `Double`, `Float8` | `Float64` |
325+
| `Timestamp_s`, `Timestamp_sec`, `Timestamp(0)` | `TimestampSecond` |
326+
| `Timestamp`, `Timestamp_ms`, `Timestamp(3)` | `TimestampMillisecond` |
327+
| `Timestamp_us`, `Timestamp(6)` | `TimestampMicroSecond` |
328+
| `Timestamp_ns`, `Timestamp(9)` | `TimestampNanosecond` |
329+
330+
:::warning 注意
331+
类型别名 `Int2``Int4``Int8``Float4``Float8` 遵循 PostgreSQL 和 MySQL 的约定,这些标识符表示类型中的**字节**数(而非位数)。
332+
333+
具体来说:
334+
- `Int2` = 2 字节 = `SmallInt`(16 位)
335+
- `Int4` = 4 字节 = `Int`(32 位)
336+
- `Int8` = 8 字节 = `BigInt`(64 位)
337+
- `Float4` = 4 字节 = `Float`(32 位)
338+
- `Float8` = 8 字节 = `Double`(64 位)
339+
340+
注意:GreptimeDB 的原生类型名称(如 `UInt8``Int32``Int64`)表示****数,而 SQL 类型别名 `Int2``Int4``Int8` 遵循 PostgreSQL/MySQL 约定表示**字节**数。例如,原生类型 `Int8` 是 8 ****整数(`TinyInt`, 1 字节),而 SQL 别名 `INT8` 映射到 8 **字节**整数(`BigInt`,64 位)。
341+
:::
324342

325343
在创建表时也可以使用这些别名类型。
326344
例如,使用 `Varchar` 代替 `String`,使用 `Double` 代替 `Float64`,使用 `Timestamp(0)` 代替 `TimestampSecond`

0 commit comments

Comments
 (0)