

 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] NAME
<a name="rsql-query-tool-describe-s-plus-named"></a>

테이블, 보기 또는 인덱스에 대해 설명합니다. 열 이름 및 유형을 포함합니다. 또한 diststyle, 백업 구성, 생성 날짜(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)
```

테이블의 배포 스타일 또는 *Diststyle*은 KEY, AUTO, EVEN 또는 ALL일 수 있습니다.

*백업(Backup)*은 스냅샷이 생성될 때 테이블이 백업되는지 여부를 나타냅니다. 유효한 값은 `YES` 또는 `NO`입니다.

*생성됨(Created)*은 테이블이 생성될 때의 타임스탬프입니다. 2018년 11월 이전에 생성된 Amazon Redshift 테이블에는 생성 날짜를 사용할 수 없습니다. 이 날짜 이전에 생성된 테이블은 n/a(해당 사항 없음)으로 표시됩니다.

*고유 제약 조건(Unique Constraints)*에는 테이블에 대한 고유 및 기본 키 제약 조건이 나열됩니다.

*외래 키 제약 조건(Foreign-key constraints)*에는 테이블에 대한 외래 키 제약 조건이 나열됩니다.

## \$1dC[\$1] [PATTERN]
<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] [PATTERN]
<a name="rsql-query-tool-describe-dds"></a>

다른 곳에 표시되지 않는 객체 설명을 보여줍니다.

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

외부 테이블을 나열합니다. 여기에는 AWS Glue Data Catalog의 테이블, Hive Metastore 및 Amazon RDS/Aurora MySQL, Amazon RDS/Aurora PostgreSQL 및 Amazon Redshift 데이터 공유 테이블의 페더레이션 테이블이 포함됩니다.

## \$1de NAME
<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] [PATTERN]
<a name="rsql-query-tool-df"></a>

 다양한 유형의 함수를 나열합니다. 예를 들어 `\df` 명령은 함수 목록을 반환합니다. 결과에는 이름, 반환된 데이터 유형, 액세스 권한 및 추가 메타데이터와 같은 속성이 포함됩니다. 함수 유형에는 트리거, 저장 프로시저, 윈도 함수 및 기타 유형이 포함될 수 있습니다. 명령에 `S+`를 추가하면(예: `\dfantS+`) `owner`, `security`, `access privileges` 등의 추가 메타데이터 열이 포함됩니다.

## \$1dL[S\$1] [PATTERN]
<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] [PATTERN]
<a name="rsql-query-tool-describe-dm"></a>

 구체화된 보기를 나열합니다. 예를 들어 `\dmS+`는 구체화된 보기와 해당 속성을 나열합니다. 명령에 `S+`를 추가하면 추가 메타데이터 열이 포함됩니다.

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

 스키마를 나열합니다. 명령에 `S+`를 추가하면(예: `\dnS+`) `description`, `access privileges`등의 추가 메타데이터 열이 포함됩니다.

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

 테이블, 보기 및 시퀀스 액세스 권한을 나열합니다.

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

 테이블을 나열합니다. 명령에 `S+`를 추가하면(예: `\dtS+`) 이 경우 `description` 등의 추가 메타데이터 열이 포함됩니다.

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

 데이터베이스의 사용자를 나열합니다. 해당 이름과 슈퍼 사용자 및 속성 등의 역할을 포함합니다.

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

 보기를 나열합니다. 스키마, 유형 및 소유자 데이터를 포함합니다. 명령에 `S+`를 추가하면(예:`\dvS+`) 추가 메타데이터 열이 포함됩니다.

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

 HTML 출력을 설정합니다. 이는 형식이 지정된 결과를 빠르게 반환하는 데 유용합니다. 예를 들어 `select * from sales; \H`는 sales 테이블의 결과를 HTML로 반환합니다. 테이블형 결과로 다시 전환하려면 `\q` 또는 quiet을 사용합니다.

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

 파일에서 명령을 실행합니다. 예를 들어, 작업 디렉터리에 rsql\$1steps.sql이 있다고 가정하면 `\i rsql_steps.sql`은 파일에서 명령을 실행합니다.

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

 데이터베이스를 나열합니다. 소유자, 인코딩 및 추가 정보가 포함됩니다.

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

 quit 또는 `\q` 명령은 데이터베이스 세션을 로그오프하고 RSQL을 종료합니다.

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

 보기의 정의를 표시합니다.

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

 예를 들어 쿼리의 실행 시간을 표시합니다.

## \$1z [PATTERN]
<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>

 RSQL이 후속 SQL SELECT 문에서 반환하는 데이터베이스 정보를 저장하는 데 사용하는 내보내기 파일의 이름을 지정합니다.

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` 명령에 대한 기본 호스트 이름이 됩니다. 기본 호스트 이름을 변경하려면 추가 `\LOGON` 명령에 새 `HOST`를 지정합니다.

`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*와 같은 bash 옵션이나 *--<arg>*와 같은 인수의 옵션을 지원하지 않습니다.

다음과 같은 변수를 설정합니다.
+ ERRORLEVEL
+ HEADING 및 RTITLE
+ RFORMAT
+ MAXERROR
+ TITLEDASHES
+ WIDTH

다음 예에서는 헤딩을 지정합니다.

```
\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`는 파라미터로 전달된 운영 체제 명령을 실행합니다. 명령이 실행되면 컨트롤이 Amazon Redshift RSQL로 돌아갑니다. 예를 들어, `\os date` 명령을 실행하여 현재 시스템 날짜 시간을 인쇄하고 RSQL 터미널로 돌아갈 수 있습니다.

```
(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`를 사용하여 코드 실행 방법을 제어합니다.