> For the complete documentation index, see [llms.txt](https://docs.codatum.jp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.codatum.jp/data-exploration/parameter-overview/dynamic-select-options.md).

# 動的な選択肢の生成

[テキスト選択](/data-exploration/parameter-overview/parameter-types.md#text-select)や[テキスト複数選択](/data-exploration/parameter-overview/parameter-types.md#text-multi-select)では、3種類の選択肢の生成方法をサポートしています。

## 1. `固定リスト`

固定の値から選択したい場合に使用します。

* 設定:
  * CSV Text:
    * CSV形式のテキストで選択肢を定義します。各項目は改行で区切ります。表示名を指定する場合は、同じ行にカンマ（,）で区切って記述します。

例：

```csv
value1,表示名1
value2,表示名2
```

## 2. `テーブル`

特定のテーブルのカラムから選択可能な値を生成したい場合に使用します。

* 設定:
  * `テーブル`: 値を取得するテーブルを選択します。
  * `選択肢にするカラム`: 選択肢の値として使用するカラムを指定します。
  * `表示名にするカラム`: 表示ラベルとして使用するカラムを指定します。

## 3. `クエリ実行結果`

指定したSQLの実行結果に基づいて選択肢を生成したい場合に使用します。

* 設定:
  * `コネクション`:
    * クエリに使用するデータベース接続を選択します。
  * `SQL`:
    * 選択肢の値を返すSQLを入力します。クエリが複数のカラムを返す場合、最初のカラムが選択肢の値として、2番目のカラム（存在する場合）が表示ラベルとして使用されます。

{% hint style="info" %}
選択肢用のSQLは頻繁に実行されるため、パフォーマンスを最適化するために、遅いクエリやリソースを多く消費するクエリの使用は避けてください。
{% endhint %}

## SQLの実行タイミング

パラメータの選択肢にSQLを使用する場合、以下のタイミングでクエリが実行されます：

1. **ノートブックページが読み込まれたとき**：
   * そのページで使用されているパラメータのSQLはページの初期化時に実行されます
   * 現在のページで使用されていないパラメータは初期化されず、そのSQLも実行されません
2. **パラメータのドロップダウンが開かれたとき**：
   * ドロップダウンメニューが最初に開かれたときにSQLクエリが実行されます
3. **検索フィールドに入力するとき**：
   * 初回のクエリ実行後は、すでに取得したデータを使用してクライアント側でフィルタリングが行われます
   * キーストロークごとにSQLが再実行されることはありません

## キャッシュの動作

パラメータ用のSQLは、通常のSQLブロックと同じキャッシュメカニズムを使用します：

* 結果はバックエンドで最大24時間キャッシュされます
* 同一のクエリ（パラメータ値を含む）はキャッシュされた結果を使用します
* フロントエンドも現在のセッション中はメモリキャッシュを維持します

これにより、パラメータ選択のドロップダウンが頻繁に開かれたとしても、実際のクエリはキャッシュ期間内に1回だけ実行され、パフォーマンスが大幅に向上します。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.codatum.jp/data-exploration/parameter-overview/dynamic-select-options.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
