> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-3a82795f.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> ClickHouse의 FixedString 데이터 타입에 대한 문서

# FixedString(N)

`N`바이트 길이의 고정 문자열입니다(문자 수나 코드 포인트 수 기준이 아님).

`FixedString` 타입의 컬럼을 선언하려면 다음 구문을 사용합니다:

```sql theme={null}
<column_name> FixedString(N)
```

여기서 `N`은 자연수입니다.

`FixedString` 타입은 데이터 길이가 정확히 `N`바이트일 때 효율적입니다. 그 외의 경우에는 오히려 효율이 떨어질 가능성이 높습니다.

`FixedString` 타입이 지정된 컬럼에 효율적으로 저장할 수 있는 값의 예시는 다음과 같습니다.

* IP 주소의 이진 표현 (`FixedString(16)`은 IPv6에 사용).
* 언어 코드 (ru\_RU, en\_US ... ).
* 통화 코드 (USD, RUB ... ).
* 해시의 이진 표현 (`FixedString(16)`은 MD5에, `FixedString(32)`는 SHA256에 사용).

UUID 값을 저장하려면 [UUID](/ko/reference/data-types/uuid) 데이터 타입을 사용하십시오.

데이터를 삽입할 때 ClickHouse는 다음과 같이 동작합니다.

* 문자열이 `N`바이트보다 적으면 null byte를 추가해 문자열을 채웁니다.
* 문자열이 `N`바이트보다 많으면 `Too large value for FixedString(N)` 예외를 발생시킵니다.

다음과 같은, `FixedString(2)` 컬럼 하나만 있는 테이블을 살펴보겠습니다.

```sql theme={null}

INSERT INTO FixedStringTable VALUES ('a'), ('ab'), ('');
```

```sql theme={null}
SELECT
    name,
    toTypeName(name),
    length(name),
    empty(name)
FROM FixedStringTable;
```

```text theme={null}
┌─name─┬─toTypeName(name)─┬─length(name)─┬─empty(name)─┐
│ a    │ FixedString(2)   │            2 │           0 │
│ ab   │ FixedString(2)   │            2 │           0 │
│      │ FixedString(2)   │            2 │           1 │
└──────┴──────────────────┴──────────────┴─────────────┘
```

`FixedString(N)` 값의 길이는 고정되어 있다는 점에 유의하십시오. [length](/ko/reference/functions/regular-functions/array-functions#length) 함수는 `FixedString(N)` 값이 null byte로만 채워져 있어도 `N`을 반환하지만, 이 경우 [empty](/ko/reference/functions/regular-functions/array-functions#empty) 함수는 `1`을 반환합니다.

`WHERE` 절로 데이터를 조회할 때는 조건을 어떻게 지정하느냐에 따라 결과가 달라집니다.

* 동등 연산자 `=`, `==` 또는 `equals` 함수를 사용하면 ClickHouse는 `\0` 문자를 고려하지 *않습니다*. 즉, 쿼리 `SELECT * FROM FixedStringTable WHERE name = 'a';` 와 `SELECT * FROM FixedStringTable WHERE name = 'a\0';` 는 동일한 결과를 반환합니다.
* `LIKE` 절을 사용하면 ClickHouse는 `\0` 문자를 *고려합니다*. 따라서 필터 조건에 `\0` 문자를 명시적으로 지정해야 할 수 있습니다.

```sql theme={null}
SELECT name
FROM FixedStringTable
WHERE name = 'a'
FORMAT JSONStringsEachRow

{"name":"a\u0000"}

SELECT name
FROM FixedStringTable
WHERE name = 'a\0'
FORMAT JSONStringsEachRow

{"name":"a\u0000"}

SELECT name
FROM FixedStringTable
WHERE name = 'a'
FORMAT JSONStringsEachRow

Query id: c32cec28-bb9e-4650-86ce-d74a1694d79e

{"name":"a\u0000"}

SELECT name
FROM FixedStringTable
WHERE name LIKE 'a'
FORMAT JSONStringsEachRow

0 rows in set.

SELECT name
FROM FixedStringTable
WHERE name LIKE 'a\0'
FORMAT JSONStringsEachRow

{"name":"a\u0000"}
```
