> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# cast_* セッション設定

> cast_* 生成グループに含まれる ClickHouse のセッション設定。

export const SettingsInfoBlock = ({type, default_value, changeable_without_restart}) => {
  return <div className="not-prose" style={{
    display: "flex",
    flexWrap: "wrap",
    alignItems: "baseline",
    columnGap: "0.5rem",
    rowGap: "0.125rem",
    margin: "0.375rem 0",
    fontSize: "0.8125rem",
    lineHeight: "1.125rem"
  }}>
      <div style={{
    fontWeight: 600,
    opacity: 0.72
  }}>型</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{type}</div>
      <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>デフォルト値</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{default_value}</div>
      {changeable_without_restart && <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>
          再起動せずに変更可能
        </div>}
      {changeable_without_restart && <div style={{
    overflowWrap: "anywhere"
  }}>
          {changeable_without_restart}
        </div>}
    </div>;
};

これらの設定は、[system.settings](/docs/ja/reference/system-tables/settings)で利用でき、[ソース](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp)から自動生成されています。

<div id="cast_ipv4_ipv6_default_on_conversion_error">
  ## cast\_ipv4\_ipv6\_default\_on\_conversion\_error
</div>

<SettingsInfoBlock type="Bool" default_value="0" />

<VersionHistory rows={[{"id": "row-1","items": [{"label": "22.3"},{"label": "0"},{"label": "cast(value, 'IPv4') および cast(value, 'IPv6') 関数が、toIPv4 関数および toIPv6 関数と同様に動作するようにする"}]}]} />

IPv4 への CAST 演算子、IPv6 型への CAST 演算子、toIPv4 関数、および toIPv6 関数は、変換エラー時に例外をスローする代わりにデフォルト値を返します。

<div id="cast_keep_nullable">
  ## cast\_keep\_nullable
</div>

<SettingsInfoBlock type="Bool" default_value="0" />

[CAST](/docs/ja/reference/functions/regular-functions/type-conversion-functions#CAST) 操作で `Nullable` データ型を保持するかどうかを設定します。

この設定を有効にしていて、`CAST` 関数の引数が `Nullable` の場合、結果も `Nullable` 型に変換されます。この設定が無効な場合、結果は常に宛先の型そのものになります。

設定可能な値:

* 0 — `CAST` の結果は、指定した宛先の型そのものになります。
* 1 — 引数の型が `Nullable` の場合、`CAST` の結果は `Nullable(DestinationDataType)` に変換されます。

**例**

次のクエリでは、結果は宛先のデータ型そのものになります。

```sql theme={null}
SET cast_keep_nullable = 0;
SELECT CAST(toNullable(toInt32(0)) AS Int32) as x, toTypeName(x);
```

結果:

```text theme={null}
┌─x─┬─toTypeName(CAST(toNullable(toInt32(0)), 'Int32'))─┐
│ 0 │ Int32                                             │
└───┴───────────────────────────────────────────────────┘
```

次のクエリの結果、宛先のデータ型に `Nullable` 修飾子が適用されます。

```sql theme={null}
SET cast_keep_nullable = 1;
SELECT CAST(toNullable(toInt32(0)) AS Int32) as x, toTypeName(x);
```

結果:

```text theme={null}
┌─x─┬─toTypeName(CAST(toNullable(toInt32(0)), 'Int32'))─┐
│ 0 │ Nullable(Int32)                                   │
└───┴───────────────────────────────────────────────────┘
```

**関連項目**

* [CAST](/docs/ja/reference/functions/regular-functions/type-conversion-functions#CAST) 関数
