

 Amazon Redshift は、パッチ 198 以降、新しい Python UDF の作成をサポートしなくなります。既存の Python UDF は、2026 年 6 月 30 日まで引き続き機能します。詳細については、[ブログ記事](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)を参照してください。

# Amazon Redshift RSQL メタコマンド
<a name="rsql-query-tool-commands"></a>

Amazon Redshift RSQL メタコマンドは、データベース、または特定のデータベースオブジェクトに関する情報レコードを返します。結果には、さまざまな列とメタデータを含めることができます。その他のコマンドは、特定のアクションを実行します。これらのコマンドの先頭にはバックスラッシュが付きます。

## \$1d[S\$1]
<a name="rsql-query-tool-describe-d"></a>

 ユーザーが作成したローカルテーブル、レギュラービュー、レイトバインディングビュー、マテリアライズドビューを一覧表示します。`\dS `も`\d`と同様に、テーブルとビューを一覧表示しますが、システムオブジェクトは返されたレコードに含まれます。`+`の結果、一覧表示されたすべてのオブジェクトの追加メタデータ列`description`が表示されます。次に、コマンドの結果として返されるサンプルレコードを示します。

```
List of relations
 schema |   name    | type  |  owner  
--------+-----------+-------+---------
 public | category  | table | awsuser
 public | date      | table | awsuser
 public | event     | table | awsuser
 public | listing   | table | awsuser
 public | sales     | table | awsuser
 public | users     | table | awsuser
 public | venue     | table | awsuser
(7 rows)
```

## \$1d[S\$1] 名前
<a name="rsql-query-tool-describe-s-plus-named"></a>

テーブル、ビュー、またはインデックスについて説明します。列の名前と型が含まれます。また、distststyle、バックアップ設定、作成日 (2018 年 10 月以降に作成されたテーブル）、および制約条件を提供します。たとえば、`\dS+ sample`はオブジェクトのプロパティを返します。`S+`を付けると、返されたレコードに含まれる追加の列が表示されます。

```
Table "public.sample"
 Column |            Type             |   Collation    | Nullable | Default Value | Encoding  | DistKey | SortKey
--------+-----------------------------+----------------+----------+---------------+-----------+---------+---------
 col1   | smallint                    |                | NO       |               | none      | t       | 1
 col2   | character(100)              | case_sensitive | YES      |               | none      | f       | 2
 col3   | character varying(100)      | case_sensitive | YES      |               | text32k   | f       | 3
 col4   | timestamp without time zone |                | YES      |               | runlength | f       | 0
 col5   | super                       |                | YES      |               | zstd      | f       | 0
 col6   | bigint                      |                | YES      |               | az64      | f       | 0

Diststyle: KEY
Backup: YES
Created: 2021-07-20 19:47:27.997045
Unique Constraints:
    "sample_pkey" PRIMARY KEY (col1)
    "sample_col2_key" UNIQUE (col2)
Foreign-key constraints:
    "sample_col2_fkey" FOREIGN KEY (col2) REFERENCES lineitem(l_orderkey)
```

テーブルのディストリビューションスタイル、または*ディストスタイル*は、KEY、AUTO、EVEN または ALL のいずれかです。

*バックアップ*は、スナップショットの作成時にテーブルがバックアップされるかどうかを示します。有効な値は `YES` または `NO` です。

*作成*は、テーブルが作成された時刻のタイムスタンプです。2018 年 11 月より前に作成された Amazon Redshift テーブルでは、作成日は使用できません。この日付より前に作成されたテーブルには「なし」と表示されます (使用不可）。

*ユニーク制約*は、テーブルにユニーク制約とプライマリキー制約を一覧表示します。

*外部キー制約*は、テーブルに外部キー制約を一覧表示します。

## \$1dC[\$1] [パターン]
<a name="rsql-query-tool-describe-dc"></a>

キャストを一覧表示します。ソースタイプ、ターゲットタイプ、およびキャストが暗黙的かどうかが含まれます。

次に、`\dC+`からの結果のサブセットを示します。

```
List of casts
         source type         |         target type         |      function       |   implicit?   | description 
-----------------------------+-----------------------------+---------------------+---------------+-------------
 "char"                      | character                   | bpchar              | in assignment | 
 "char"                      | character varying           | text                | in assignment | 
 "char"                      | integer                     | int4                | no            | 
 "char"                      | text                        | text                | yes           | 
 "path"                      | point                       | point               | no            | 
 "path"                      | polygon                     | polygon             | in assignment | 
 abstime                     | date                        | date                | in assignment | 
 abstime                     | integer                     | (binary coercible)  | no            | 
 abstime                     | time without time zone      | time                | in assignment | 
 abstime                     | timestamp with time zone    | timestamptz         | yes           | 
 abstime                     | timestamp without time zone | timestamp           | yes           | 
 bigint                      | bit                         | bit                 | no            | 
 bigint                      | boolean                     | bool                | yes           | 
 bigint                      | character                   | bpchar              | in assignment | 
 bigint                      | character varying           | text                | in assignment | 
 bigint                      | double precision            | float8              | yes           | 
 bigint                      | integer                     | int4                | in assignment | 
 bigint                      | numeric                     | numeric             | yes           | 
 bigint                      | oid                         | oid                 | yes           | 
 bigint                      | real                        | float4              | yes           | 
 bigint                      | regclass                    | oid                 | yes           | 
 bigint                      | regoper                     | oid                 | yes           | 
 bigint                      | regoperator                 | oid                 | yes           | 
 bigint                      | regproc                     | oid                 | yes           | 
 bigint                      | regprocedure                | oid                 | yes           | 
 bigint                      | regtype                     | oid                 | yes           | 
 bigint                      | smallint                    | int2                | in assignment | 
 bigint                      | super                       | int8_partiql        | in assignment |
```

## \$1dd[S] [パターン]
<a name="rsql-query-tool-describe-dds"></a>

他の場所では表示されないオブジェクトの説明が表示されます。

## \$1de
<a name="rsql-query-tool-describe-de"></a>

外部テーブルを一覧表示します。これには、AWS Glue Data Catalog のテーブル、Hive メタストア、Amazon RDS/Aurora MySQL、Amazon RDS/Aurora PostgreSQL、Amazon Redshift のデータ共有テーブルからの連携テーブルが含まれます。

## \$1de 名前
<a name="rsql-query-tool-describe-de-name"></a>

外部テーブルについて説明します。

次のサンプルは、AWS Glue外部テーブルを示しています。

```
# \de spectrum.lineitem
                            Glue External table "spectrum.lineitem"
     Column      | External Type | Redshift Type | Position | Partition Key | Nullable
-----------------+---------------+---------------+----------+---------------+----------
 l_orderkey      | bigint        | bigint        | 1        | 0             |
 l_partkey       | bigint        | bigint        | 2        | 0             |
 l_suppkey       | int           | int           | 3        | 0             |
 l_linenumber    | int           | int           | 4        | 0             |
 l_quantity      | decimal(12,2) | decimal(12,2) | 5        | 0             |
 l_extendedprice | decimal(12,2) | decimal(12,2) | 6        | 0             |
 l_discount      | decimal(12,2) | decimal(12,2) | 7        | 0             |
 l_tax           | decimal(12,2) | decimal(12,2) | 8        | 0             |
 l_returnflag    | char(1)       | char(1)       | 9        | 0             |
 l_linestatus    | char(1)       | char(1)       | 10       | 0             |
 l_shipdate      | date          | date          | 11       | 0             |
 l_commitdate    | date          | date          | 12       | 0             |
 l_receiptdate   | date          | date          | 13       | 0             |
 l_shipinstruct  | char(25)      | char(25)      | 14       | 0             |
 l_shipmode      | char(10)      | char(10)      | 15       | 0             |
 l_comment       | varchar(44)   | varchar(44)   | 16       | 0             |

Location: s3://redshiftbucket/kfhose2019/12/31
Input_format: org.apache.hadoop.mapred.TextInputFormat
Output_format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
Serialization_lib: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
Serde_parameters: {"field.delim":"|","serialization.format":"|"}
Parameters: {"EXTERNAL":"TRUE","numRows":"178196721475","transient_lastDdlTime":"1577771873"}
```

Hive メタストアテーブル。

```
# \de emr.lineitem
                     Hive Metastore External Table "emr.lineitem"
     Column      | External Type | Redshift Type | Position | Partition Key | Nullable
-----------------+---------------+---------------+----------+---------------+----------
 l_orderkey      | bigint        | bigint        | 1        | 0             |
 l_partkey       | bigint        | bigint        | 2        | 0             |
 l_suppkey       | int           | int           | 3        | 0             |
 l_linenumber    | int           | int           | 4        | 0             |
 l_quantity      | decimal(12,2) | decimal(12,2) | 5        | 0             |
 l_extendedprice | decimal(12,2) | decimal(12,2) | 6        | 0             |
 l_discount      | decimal(12,2) | decimal(12,2) | 7        | 0             |
 l_tax           | decimal(12,2) | decimal(12,2) | 8        | 0             |
 l_returnflag    | char(1)       | char(1)       | 9        | 0             |
 l_linestatus    | char(1)       | char(1)       | 10       | 0             |
 l_commitdate    | date          | date          | 11       | 0             |
 l_receiptdate   | date          | date          | 12       | 0             |
 l_shipinstruct  | char(25)      | char(25)      | 13       | 0             |
 l_shipmode      | char(10)      | char(10)      | 14       | 0             |
 l_comment       | varchar(44)   | varchar(44)   | 15       | 0             |
 l_shipdate      | date          | date          | 16       | 1             |

Location: s3://redshiftbucket/cetas
Input_format: org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat
Output_format: org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat
Serialization_lib: org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe
Serde_parameters: {"serialization.format":"1"}
Parameters: {"EXTERNAL":"TRUE", "numRows":"4307207", "transient_lastDdlTime":"1626990007"}
```

PostgreSQL 外部テーブル。

```
# \de pgrsql.alltypes
                                Postgres Federated Table "pgrsql.alltypes"
 Column |        External Type        |        Redshift Type        | Position | Partition Key | Nullable
--------+-----------------------------+-----------------------------+----------+---------------+----------
 col1   | bigint                      | bigint                      | 1        | 0             |
 col2   | bigint                      | bigint                      | 2        | 0             |
 col5   | boolean                     | boolean                     | 3        | 0             |
 col6   | box                         | varchar(65535)              | 4        | 0             |
 col7   | bytea                       | varchar(65535)              | 5        | 0             |
 col8   | character(10)               | character(10)               | 6        | 0             |
 col9   | character varying(10)       | character varying(10)       | 7        | 0             |
 col10  | cidr                        | varchar(65535)              | 8        | 0             |
 col11  | circle                      | varchar(65535)              | 9        | 0             |
 col12  | date                        | date                        | 10       | 0             |
 col13  | double precision            | double precision            | 11       | 0             |
 col14  | inet                        | varchar(65535)              | 12       | 0             |
 col15  | integer                     | integer                     | 13       | 0             |
 col16  | interval                    | varchar(65535)              | 14       | 0             |
 col17  | json                        | varchar(65535)              | 15       | 0             |
 col18  | jsonb                       | varchar(65535)              | 16       | 0             |
 col19  | line                        | varchar(65535)              | 17       | 0             |
 col20  | lseg                        | varchar(65535)              | 18       | 0             |
 col21  | macaddr                     | varchar(65535)              | 19       | 0             |
 col22  | macaddr8                    | varchar(65535)              | 20       | 0             |
 col23  | money                       | varchar(65535)              | 21       | 0             |
 col24  | numeric                     | numeric(38,20)              | 22       | 0             |
 col25  | path                        | varchar(65535)              | 23       | 0             |
 col26  | pg_lsn                      | varchar(65535)              | 24       | 0             |
 col28  | point                       | varchar(65535)              | 25       | 0             |
 col29  | polygon                     | varchar(65535)              | 26       | 0             |
 col30  | real                        | real                        | 27       | 0             |
 col31  | smallint                    | smallint                    | 28       | 0             |
 col32  | smallint                    | smallint                    | 29       | 0             |
 col33  | integer                     | integer                     | 30       | 0             |
 col34  | text                        | varchar(65535)              | 31       | 0             |
 col35  | time without time zone      | varchar(65535)              | 32       | 0             |
 col36  | time with time zone         | varchar(65535)              | 33       | 0             |
 col37  | timestamp without time zone | timestamp without time zone | 34       | 0             |
 col38  | timestamp with time zone    | timestamp with time zone    | 35       | 0             |
 col39  | tsquery                     | varchar(65535)              | 36       | 0             |
 col40  | tsvector                    | varchar(65535)              | 37       | 0             |
 col41  | txid_snapshot               | varchar(65535)              | 38       | 0             |
 col42  | uuid                        | varchar(65535)              | 39       | 0             |
 col43  | xml                         | varchar(65535)              | 40       | 0             |
```

## \$1df[anptw][S\$1] [パターン]
<a name="rsql-query-tool-df"></a>

 さまざまなタイプの関数を一覧表示します。例えば、コマンド`\df`は関数のリストを返します。結果には、名前、返されたデータタイプ、アクセス権、追加のメタデータなどのプロパティが含まれます。関数の種類には、トリガー、ストアドプロシージャ、window 関数、およびその他のものがあります。例えば`S+`をコマンド`\dfantS+`に追加すると、`owner`、`security`、および`access privileges`などのメタデータ列が追加されます。

## \$1dL[S\$1] [パターン]
<a name="rsql-query-tool-describe-dl"></a>

 データベースに関連付けられている手続き言語に関するデータを一覧表示します。情報には、plpgsql などの名前と、信頼できるかどうかを含んだ追加のメタデータ、アクセス権限、および説明が含まれます。サンプル呼び出しは、例えば`\dLS+`であり、言語とそのプロパティが一覧表示されます。`S+`をコマンドに追加すると、`call handler`および`access privileges`などのメタデータ列が追加されます。

サンプル結果:

```
List of languages
   name    | trusted | internal language |      call handler       |                         validator                          | access privileges |          description           
-----------+---------+-------------------+-------------------------+------------------------------------------------------------+-------------------+--------------------------------
 c         | f       | t                 | -                       | fmgr_c_validator(oid)                                      |                   | Dynamically-loaded C functions
 exfunc    | f       | f                 | exfunc_call_handler()   | -                                                          | rdsdb=U/rdsdb     | 
 internal  | f       | t                 | -                       | fmgr_internal_validator(oid)                               |                   | Built-in functions
 mlfunc    | f       | f                 | mlfunc_call_handler()   | -                                                          | rdsdb=U/rdsdb     | 
 plpgsql   | t       | f                 | plpgsql_call_handler()  | plpgsql_validator(oid)                                     |                   | 
 plpythonu | f       | f                 | plpython_call_handler() | plpython_compiler(cstring,cstring,cstring,cstring,cstring) | rdsdb=U/rdsdb     | 
 sql       | t       | t                 | -                       | fmgr_sql_validator(oid)                                    | =U/rdsdb          | SQL-language functions
```

## \$1dm[S\$1] [パターン]
<a name="rsql-query-tool-describe-dm"></a>

 マテリアライズドビューを一覧表示します。例えば、`\dmS+`は、マテリアライズドビューとそのプロパティを一覧表示します。`S+`をコマンドに追加すると、メタデータ列が追加されます。

## \$1dn[S\$1] [パターン]
<a name="rsql-query-tool-describe-dn"></a>

 スキーマを一覧表示します。例えば、`S+`を`\dnS+`のコマンドに追加すると、`description`および`access privileges`などの追加のメタデータ列が追加されます。

## \$1dp [パターン]
<a name="rsql-query-tool-describe-dp"></a>

 テーブル、ビューおよびシーケンスのアクセス権限を一覧表示します。

## \$1dt[S\$1] [パターン]
<a name="rsql-query-tool-describe-dt"></a>

 テーブルの一覧表示 例えば、`S+`をコマンド`\dtS+`に追加すると、この場合`description`のようなメタデータ列が追加されます。

## \$1du
<a name="rsql-query-tool-describe-du"></a>

 データベースのユーザーを一覧表示します。名前とスーパーユーザーなどのロール、属性が含まれます。

## \$1dv[S\$1] [パターン]
<a name="rsql-query-tool-describe-dv"></a>

 ビューを一覧表示します。スキーマ、タイプ、および所有者データが含まれます。例えば、`S+`をコマンド`\dvS+`に追加すると、メタデータ列が追加されます。

## \$1H
<a name="rsql-query-tool-describe-h"></a>

 HTML 出力をオンにします。これは、フォーマットされた結果をすばやく返す場合に便利です。例えば、`select * from sales; \H`は、売上表の結果を HTML で返します。結果を表形式に戻すには、`\q`または quiet を使用します。

## \$1i
<a name="rsql-query-tool-describe-i"></a>

 ファイルからコマンドを実行します。例えば、作業ディレクトリに rsql\$1steps.sql があると仮定すると、次のものがファイルのコマンドを実行します。`\i rsql_steps.sql`。

## \$1l[\$1] [パターン]
<a name="rsql-query-tool-describe-l"></a>

 データベースを一覧表示します。所有者、エンコード、および追加情報が含まれます。

## \$1q
<a name="rsql-query-tool-describe-q"></a>

 quit または `\q` コマンドを実行して、データベースセッションからログオフし、RSQL を終了します。

## \$1sv[\$1] ビュー名
<a name="rsql-query-tool-describe-sv-name"></a>

 ビューの定義を表示します。

## \$1timing
<a name="rsql-query-tool-describe-timing"></a>

 例えば、クエリのランタイムが表示されます。

## \$1z [パターン]
<a name="rsql-query-tool-describe-z"></a>

 \$1dpと同じ出力です。

## \$1?
<a name="rsql-query-tool-help"></a>

 ヘルプ情報を表示します。オプションのパラメータにより、表示する項目を指定します。

## \$1EXIT
<a name="rsql-query-tool-flow-control-exit"></a>

 すべてのデータベースセッションからログオフし、Amazon Redshift RSQL を終了します。加えて、オプションの終了コードを指定することも可能です。例えば `\EXIT 15` では、Amazon Redshift の RSQL ターミナルを終了し、その際に終了コードとして 15 を返します。

次の例は、接続からの出力と RSQL からの終了を示しています。

```
% rsql -D testuser
DSN Connected
DBMS Name: Amazon Redshift
Driver Name: Amazon Redshift ODBC Driver
Driver Version: 1.4.34.1000
Rsql Version: 1.0.1
Redshift Version: 1.0.29306 
Type "help" for help.

(testcluster) user1@dev=# \exit 15

% echo $?
15
```

## \$1EXPORT
<a name="rsql-query-tool-export"></a>

 後続の SQL SELECT ステートメントによって返されたデータベース情報を保存するために RSQL が使用するエクスポートファイルの名前を指定します。

export\$101.sql

```
\export report file='E:\\accounts.out'
\rset rformat off
\rset width 1500
\rset heading "General Title"
\rset titledashes on
select * from td_dwh.accounts;
\export reset
```

コンソール出力

```
Rformat is off.
Target width is 1500.
Heading is set to: General Title
Titledashes is on.
(exported 40 rows)
```

## \$1LOGON
<a name="rsql-query-tool-flow-control-logon"></a>

 データベースに接続します。接続パラメータは、位置指定の構文を使って指定することも、接続文字列として指定することもできます。　

コマンドの構文は次のとおりです。`\logon {[DBNAME|- USERNAME|- HOST|- PORT|- [PASSWORD]] | conninfo}`

`DBNAME` は、接続先に指定するデータベースの名前です。`USERNAME` は、データベースへの接続に使用するユーザー名です。`HOST` のデフォルト値は `localhost` です。`PORT` のデフォルト値は `5439` です。

`\LOGON` コマンドでホスト名を指定した場合、その名前が、追加の `\LOGON` コマンドでのデフォルトのホスト名になります。デフォルトのホスト名を変更するには、追加の `HOST` コマンドで新しく `\LOGON` を指定します。

`user1` に対する `\LOGON` コマンドの出力例を以下に示します。

```
(testcluster) user1@redshiftdb=# \logon dev
DBMS Name: Amazon Redshift
Driver Name: Amazon Redshift ODBC Driver
Driver Version: 1.4.27.1000
Rsql Version: 1.0.1
You are now connected to database "dev" as user "user1".
(testcluster) user1@dev=#
```

*user2*に対する出力例

```
(testcluster) user1@dev=# \logon dev user2 testcluster2.example.com
Password for user user2: 
DBMS Name: Amazon Redshift
Driver Name: Amazon Redshift ODBC Driver
Driver Version: 1.4.27.1000
Rsql Version: 1.0.1
You are now connected to database "dev" as user "user2" on host "testcluster2.example.com" at port "5439".
(testcluster2) user2@dev=#
```

## \$1REMARK
<a name="rsql-query-tool-flow-control-remark"></a>

 これは `\echo` コマンドの拡張です。`\REMARK` は、指定された文字列を出力ストリームに表示します。`\REMARK ` は `\echo` を拡張して、出力を改行する機能を追加したものです。

次の例は、コマンドからの出力例を示しています。

```
(testcluster) user1@dev=# \remark 'hello//world'
hello
world
```

## \$1RSET
<a name="rsql-query-tool-rset"></a>

コマンド `\rset` はコマンドのパラメータと変数を設定します。`\rset` には、インタラクティブモードとバッチモードの両方があります。*-x*、または引数 (*--<arg>* など) といった bash オプションとしてのオプションをサポートしません。

このコマンドは、以下のような変数を設定します。
+ ERRORLEVEL
+ HEADING および RTITLE
+ RFORMAT
+ MAXERROR
+ TITLEDASHES
+ WIDTH

以下の例は、HEADING を指定します。

```
\rset heading "Winter Sales Report"
```

その他の `\rset` 使用方法例については、[Amazon Redshift RSQL 変数](rsql-query-tool-variables.md)トピックに例がいくつか挙げられています。

## \$1RUN
<a name="rsql-query-tool-flow-control-run"></a>

 指定されたファイルに含まれる Amazon Redshift RSQL スクリプトを実行します。`\RUN`は`\i`コマンドを拡張して、ファイル内のヘッダー行をスキップするオプションを追加します。

ファイル名にカンマ、セミコロン、またはスペースが含まれている場合は、それを一重引用符で囲みます。また、ファイル名の後に続くテキストは、引用符で囲まれます。UNIX では、ファイル名の大文字と小文字が区別されます。Windows では、ファイル名の大文字と小文字は区別されません。

次の例は、コマンドからの出力例を示しています。

```
(testcluster) user1@dev=# \! cat test.sql
select count(*) as lineitem_cnt from lineitem;
select count(*) as customer_cnt from customer;
select count(*) as orders_cnt from orders;



(testcluster) user1@dev=# \run file=test.sql
 lineitem_cnt
--------------
      4307207
(1 row)

 customer_cnt
--------------
     37796166
(1 row)

 orders_cnt
------------
          0
(1 row)


(testcluster) user1@dev=# \run file=test.sql skip=2
2 records skipped in RUN file.
 orders_cnt
------------
          0
(1 row)
```

## \$1OS
<a name="rsql-query-tool-flow-control-os"></a>

 `\!` コマンドのエイリアスです。`\OS` は、パラメータとして渡されたオペレーションシステムコマンドを実行します。OS コマンドの実行後、コントロールは Amazon Redshift RSQL に戻されます。例えば、次のコマンドを実行して、現在のシステム日付時刻を表示し、RSQL ターミナルに戻ることができます。`\os date`。

```
(testcluster) user1@dev=# \os date
Tue Sep 7 20:47:54 UTC 2021
```

## \$1GOTO
<a name="rsql-query-tool-flow-control-goto"></a>

 Amazon Redshift RSQL 用の新しいコマンドです。`\GOTO`は、介在するコマンドをすべてスキップし、指定した`\LABEL`で処理を再開します。`\LABEL`は前方リファレンスでなければなりません。辞書的に`\GOTO`の前にある`\LABEL`にはジャンプできません。

出力例を次に示します。

```
(testcluster) user1@dev=# \! cat test.sql
select count(*) as cnt from lineitem \gset
select :cnt as cnt;
\if :cnt > 100
    \goto LABELB
\endif

\label LABELA
\remark 'this is label LABELA'
\label LABELB
\remark 'this is label LABELB'


(testcluster) user1@dev=# \i test.sql
   cnt
---------
 4307207
(1 row)

\label LABELA ignored
\label LABELB processed
this is label LABELB
```

## \$1LABEL
<a name="rsql-query-tool-flow-control-label"></a>

 Amazon Redshift RSQL 用の新しいコマンドです。`\LABEL`は、`\GOTO`コマンドのターゲットとして、プログラムを実行するためのエントリーポイントを確立します。

次の例は、コマンドからの出力例を示しています。

```
(testcluster) user1@dev=# \! cat test.sql
select count(*) from lineitem limit 5;
\goto LABELB
\remark "this step was skipped by goto label";
\label LABELA
\remark 'this is label LABELA'
\label LABELB
\remark 'this is label LABELB'



(testcluster) user1@dev=# \i testgoto.sql
  count
 4307193
(1 row)

\label LABELA ignored
\label LABELB processed
this is label LABELB
```

## \$1IF (\$1ELSEIF, \$1ELSE, \$1ENDIF)
<a name="rsql-query-tool-flow-control-if"></a>

 `\IF`、およびそれと関連するコマンドは、入力スクリプトの一部を条件付きで実行します。PSQL`\if`(`\elif`、`\else`、`\endif`) コマンドの拡張機能です。`\IF`と`\ELSEIF`は、`AND`、`OR`、`NOT`の条件を含むブール表現をサポートします。

次の例は、コマンドからの出力例を示しています。

```
(testcluster) user1@dev=# \! cat test.sql
SELECT query FROM stv_inflight LIMIT 1 \gset
select :query as query;
\if :query > 1000000
    \remark 'Query id is greater than 1000000'
\elseif :query = 1000000
    \remark 'Query id is equal than 1000000'
\else
    \remark 'Query id is less than 1000000'
\endif


(testcluster) user1@dev=# \i test.sql 
 query
--------
 994803
(1 row)
 
Query id is less than 1000000
```

ブランチロジックで `ERRORCODE` を使用する。

```
\if :'ERRORCODE' = '00000'
    \remark 'The statement was executed without error'
\else
    \remark :LAST_ERROR_MESSAGE
\endif
```

`\IF` ブロックで `\GOTO` を使用し、コードの実行方法を制御します。