Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update trainslation of fixedstring and fix the given examples of nullable in zh doc #7476

Merged
merged 2 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 53 additions & 7 deletions docs/zh/data_types/fixedstring.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,55 @@
# FixedString(N)
# FixedString

固定长度 N 的字符串。N 必须是严格的正自然数。
当服务端读取长度小于 N 的字符串时候(例如解析 INSERT 数据时),通过在字符串末尾添加空字节来达到 N 字节长度。
当服务端读取长度大于 N 的字符串时候,将返回错误消息。
当服务器写入一个字符串(例如,当输出 SELECT 查询的结果)时,NULL字节不会从字符串的末尾被移除,而是被输出。
注意这种方式与 MYSQL 的 CHAR 类型是不一样的(MYSQL 的字符串会以空格填充,然后输出的时候空格会被修剪)。
固定长度 N 的字符串(N 必须是严格的正自然数)。

与 `String` 类型相比,极少的函数会使用 `FixedString(N)`,因此使用起来不太方便。
您可以使用下面的语法对列声明为`FixedString`类型:

```sql
<column_name> FixedString(N)
```

其中`N`表示自然数。

当数据的长度恰好为N个字节时,`FixedString`类型是高效的。 在其他情况下,这可能会降低效率。

可以有效存储在`FixedString`类型的列中的值的示例:

- 二进制表示的IP地址(IPv6使用`FixedString(16)`)
- 语言代码(ru_RU, en_US ... )
- 货币代码(USD, RUB ... )
- 二进制表示的哈希值(MD5使用`FixedString(16)`,SHA256使用`FixedString(32)`)

请使用[UUID](uuid.md)数据类型来存储UUID值,。

当向ClickHouse中插入数据时,

- 如果字符串包含的字节数少于`N',将对字符串末尾进行空字节填充。
- 如果字符串包含的字节数大于`N`,将抛出`Too large value for FixedString(N)`异常。

当做数据查询时,ClickHouse不会删除字符串末尾的空字节。 如果使用`WHERE`子句,则须要手动添加空字节以匹配`FixedString`的值。 以下示例阐明了如何将`WHERE`子句与`FixedString`一起使用。

考虑带有`FixedString(2)`列的表:

```text
┌─name──┐
│ b │
└───────┘
```

查询语句`SELECT * FROM FixedStringTable WHERE a = 'b'` 不会返回任何结果。请使用空字节来填充筛选条件。

```sql
SELECT * FROM FixedStringTable
WHERE a = 'b\0'
```
```text
┌─a─┐
│ b │
└───┘
```

这种方式与MySQL的`CHAR`类型的方式不同(MySQL中使用空格填充字符串,并在输出时删除空格)。

请注意,`FixedString(N)`的长度是个常量。仅由空字符组成的字符串,函数[length](../query_language/functions/array_functions.md#array_functions-length)返回值为`N`,而函数[empty](../query_language/functions/string_functions.md#string_functions-empty)的返回值为`1`。

[来源文章](https://clickhouse.yandex/docs/en/data_types/fixedstring/) <!--hide-->
40 changes: 12 additions & 28 deletions docs/zh/data_types/nullable.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,21 @@

## 用法示例

```
:) CREATE TABLE t_null(x Int8, y Nullable(Int8)) ENGINE TinyLog

CREATE TABLE t_null
(
x Int8,
y Nullable(Int8)
)
ENGINE = TinyLog

Ok.

0 rows in set. Elapsed: 0.012 sec.

:) INSERT INTO t_null VALUES (1, NULL)

INSERT INTO t_null VALUES

Ok.

1 rows in set. Elapsed: 0.007 sec.

:) SELECT x + y FROM t_null

SELECT x + y
FROM t_null

```sql
CREATE TABLE t_null(x Int8, y Nullable(Int8)) ENGINE TinyLog
```
```sql
INSERT INTO t_null VALUES (1, NULL), (2, 3)
```
```sql
SELECT x + y FROM t_null
```
```text
┌─plus(x, y)─┐
│ ᴺᵁᴸᴸ │
│ 5 │
└────────────┘

2 rows in set. Elapsed: 0.144 sec.
```

[来源文章](https://clickhouse.yandex/docs/en/data_types/nullable/) <!--hide-->