

 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/)을 참조하세요.

# 데이터 API 호출
<a name="data-api-calling"></a>

Data API 또는 AWS CLI를 호출하여 클러스터 또는 서버리스 작업 그룹에서 SQL 문을 실행할 수 있습니다. SQL 문을 실행하는 프라이머리 작업은 *Amazon Redshift Data API 참조* 내 [https://docs.aws.amazon.com/redshift-data/latest/APIReference/API_ExecuteStatement.html](https://docs.aws.amazon.com/redshift-data/latest/APIReference/API_ExecuteStatement.html) 및 [https://docs.aws.amazon.com/redshift-data/latest/APIReference/API_BatchExecuteStatement.html](https://docs.aws.amazon.com/redshift-data/latest/APIReference/API_BatchExecuteStatement.html)입니다. Data API는 AWS SDK에서 지원되는 프로그래밍 언어를 지원합니다. 이에 대한 자세한 내용은 [AWS 기반의 도구](https://aws.amazon.com/tools/)를 참조하세요.

Data API 호출의 코드 예제를 보려면 *GitHub*에서 [Getting Started with Redshift Data API](https://github.com/aws-samples/getting-started-with-amazon-redshift-data-api#getting-started-with-redshift-data-api)를 참조하세요. 이 리포지토리에는 AWS Lambda를 사용하여 Amazon EC2, AWS Glue Data Catalog 및 Amazon SageMaker Runtime에서 Amazon Redshift 데이터에 액세스하는 예가 있습니다. 프로그래밍 언어의 예로는 Python, Go, Java 및 Javascript가 있습니다.

AWS CLI를 사용하여 Data API를 호출할 수 있습니다.

다음 예에서는 AWS CLI를 사용하여 Data API를 호출합니다. 예제를 실행하려면 환경에 맞게 파라미터 값을 편집합니다. 많은 예제에서 `cluster-identifier`가 클러스터에 대해 실행되도록 제공됩니다. 서버리스 작업 그룹에 대해 실행할 때는 `workgroup-name`을 대신 제공해야 합니다. 이 예에서는 몇 가지 Data API 작업을 보여줍니다. 자세한 내용은 *AWS CLI 명령 참조*를 참조하세요.

다음 예의 명령은 가독성을 위해 분할되고 형식이 지정되었습니다. 모든 파라미터와 응답이 모든 예시에 표시되는 것은 아닙니다. 전체 요청 구문, 요청 파라미터, 응답 구문 및 응답 요소의 API 정의는 [Amazon Redshift Data API Reference](https://docs.aws.amazon.com/redshift-data/latest/APIReference/)를 참조하세요.

# Amazon Redshift 데이터 웨어하우스에 SQL 스테이트먼트 전달
<a name="pass-sql-statements"></a>

이 페이지의 예제에서는 데이터 웨어하우스에 SQL 스테이트먼트를 전달하는 다양한 방법을 다룹니다.

## SQL 스테이트먼트 실행
<a name="data-api-calling-cli-execute-statement"></a>

SQL 문을 실행하려면 `aws redshift-data execute-statement` AWS CLI 명령을 사용합니다.

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하고 결과를 가져올 식별자를 반환합니다. 이 예에서는 AWS Secrets Manager 인증 방법을 사용합니다.

```
aws redshift-data execute-statement 
    --secret-arn arn:aws:secretsmanager:us-west-2:123456789012:secret:myuser-secret-hKgPWn 
    --cluster-identifier mycluster-test 
    --sql "select * from stl_query limit 1" 
    --database dev
```

다음은 이 응답의 예입니다.

```
{
    "ClusterIdentifier": "mycluster-test",
    "CreatedAt": 1598323175.823,
    "Database": "dev",
    "Id": "c016234e-5c6c-4bc5-bb16-2c5b8ff61814",
    "SecretArn": "arn:aws:secretsmanager:us-west-2:123456789012:secret:myuser-secret-hKgPWn"
}
```

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하고 결과를 가져올 식별자를 반환합니다. 이 예에서는 임시 자격 증명 인증 방법을 사용합니다.

```
aws redshift-data execute-statement 
    --db-user myuser 
    --cluster-identifier mycluster-test 
    --database dev 
    --sql "select * from stl_query limit 1"
```

다음은 이 응답의 예입니다.

```
{
    "ClusterIdentifier": "mycluster-test",
    "CreatedAt": 1598306924.632,
    "Database": "dev",
    "DbUser": "myuser",
    "Id": "d9b6c0c9-0747-4bf4-b142-e8883122f766"
}
```

다음 AWS CLI 명령은 서버리스 작업 그룹에 대해 SQL 문을 실행하고 결과를 가져올 식별자를 반환합니다. 이 예에서는 임시 자격 증명 인증 방법을 사용합니다.

```
aws redshift-data execute-statement 
    --database dev 
    --workgroup-name myworkgroup 
    --sql "select 1;"
```

다음은 이 응답의 예입니다.

```
{
 "CreatedAt": "2022-02-11T06:25:28.748000+00:00",
 "Database": "dev",
 "DbUser": "IAMR:RoleName",
 "Id": "89dd91f5-2d43-43d3-8461-f33aa093c41e",
 "WorkgroupName": "myworkgroup"
}
```

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하고 결과를 가져올 식별자를 반환합니다. 이 예에서는AWS Secrets Manager 인증 방법과 멱등성 토큰을 사용합니다.

```
aws redshift-data execute-statement 
    --secret-arn arn:aws:secretsmanager:us-west-2:123456789012:secret:myuser-secret-hKgPWn 
    --cluster-identifier mycluster-test 
    --sql "select * from stl_query limit 1" 
    --database dev 
    --client-token b855dced-259b-444c-bc7b-d3e8e33f94g1
```

다음은 이 응답의 예입니다.

```
{
    "ClusterIdentifier": "mycluster-test",
    "CreatedAt": 1598323175.823,
    "Database": "dev",
    "Id": "c016234e-5c6c-4bc5-bb16-2c5b8ff61814",
    "SecretArn": "arn:aws:secretsmanager:us-west-2:123456789012:secret:myuser-secret-hKgPWn"
}
```

## 파라미터가 있는 SQL 스테이트먼트 실행
<a name="data-api-calling-cli-execute-statement-parameters"></a>

SQL 문을 실행하려면 `aws redshift-data execute-statement` AWS CLI 명령을 사용합니다.

 다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하고 결과를 가져올 식별자를 반환합니다. 이 예에서는 AWS Secrets Manager 인증 방법을 사용합니다. SQL 텍스트에는 명명된 파라미터 `distance`가 있습니다. 이 경우, 조건자에 사용되는 거리는 `5`입니다. SELECT 문에서는 열 이름에 대해 명명된 파라미터를 조건자에서만 사용할 수 있습니다. SQL 문의 명명된 파라미터 값은 `parameters` 옵션에 지정됩니다.

```
aws redshift-data execute-statement 
    --secret-arn arn:aws:secretsmanager:us-west-2:123456789012:secret:myuser-secret-hKgPWn 
    --cluster-identifier mycluster-test 
    --sql "SELECT ratecode FROM demo_table WHERE trip_distance > :distance"  
    --parameters "[{\"name\": \"distance\", \"value\": \"5\"}]"
    --database dev
```

다음은 이 응답의 예입니다.

```
{
    "ClusterIdentifier": "mycluster-test",
    "CreatedAt": 1598323175.823,
    "Database": "dev",
    "Id": "c016234e-5c6c-4bc5-bb16-2c5b8ff61814",
    "SecretArn": "arn:aws:secretsmanager:us-west-2:123456789012:secret:myuser-secret-hKgPWn"
}
```

다음 예에서는 샘플 데이터베이스의 `EVENT` 테이블을 사용합니다. 자세한 내용은 *Amazon Redshift 데이터베이스 개발자 안내서*의 [EVENT 테이블](https://docs.aws.amazon.com/redshift/latest/dg/r_eventtable.html)을 참조하세요.

데이터베이스에 `EVENT` 테이블이 없으면 다음과 같이 Data API를 사용하여 생성할 수 있습니다.

```
aws redshift-data execute-statement 
--database dev
--cluster-id mycluster-test
--db-user awsuser
--sql "create table event( eventid integer not null distkey, 
                           venueid smallint not null, 
                           catid smallint not null, 
                           dateid smallint not null sortkey, 
                           eventname varchar(200), 
                           starttime timestamp)"
```

다음 명령은 `EVENT` 테이블에 한 행을 삽입합니다.

```
aws redshift-data execute-statement 
--database dev
--cluster-id mycluster-test
--db-user awsuser 
--sql "insert into event values(:eventid, :venueid::smallint, :catid, :dateid, :eventname, :starttime)" 
--parameters "[{\"name\": \"eventid\", \"value\": \"1\"}, {\"name\": \"venueid\", \"value\": \"1\"}, 
               {\"name\": \"catid\", \"value\": \"1\"}, 
               {\"name\": \"dateid\", \"value\": \"1\"}, 
               {\"name\": \"eventname\", \"value\": \"event 1\"}, 
               {\"name\": \"starttime\", \"value\": \"2022-02-22\"}]"
```

다음 명령은 `EVENT` 테이블에 두 번째 행을 삽입합니다. 이 예제에서는 다음 작업을 설명합니다.
+ `id`라는 파라미터가 SQL 텍스트에서 4번 사용됩니다.
+ 파라미터 `starttime`을 삽입할 때 암시적 형식 변환이 자동으로 적용됩니다.
+ `venueid` 열은 SMALLINT 데이터 형식으로 캐스팅됩니다.
+ DATE 데이터 형식을 나타내는 문자열은 암시적으로 TIMESTAMP 데이터 형식으로 변환됩니다.
+ 주석은 SQL 텍스트 내에서 사용할 수 있습니다.

```
aws redshift-data execute-statement 
--database dev
--cluster-id mycluster-test
--db-user awsuser 
--sql "insert into event values(:id, :id::smallint, :id, :id, :eventname, :starttime) /*this is comment, and it won't apply parameterization for :id, :eventname or :starttime here*/" 
--parameters "[{\"name\": \"eventname\", \"value\": \"event 2\"}, 
               {\"name\": \"starttime\", \"value\": \"2022-02-22\"}, 
               {\"name\": \"id\", \"value\": \"2\"}]"
```

다음은 삽입된 두 행을 보여줍니다.

```
 eventid | venueid | catid | dateid | eventname |      starttime
---------+---------+-------+--------+-----------+---------------------
       1 |       1 |     1 |      1 | event 1   | 2022-02-22 00:00:00
       2 |       2 |     2 |      2 | event 2   | 2022-02-22 00:00:00
```

다음 명령은 WHERE 절에서 명명된 파라미터를 사용하여 행을 검색합니다. 여기서 `eventid`는 `1`입니다.

```
aws redshift-data execute-statement 
--database dev
--cluster-id mycluster-test
--db-user awsuser 
--sql "select * from event where eventid=:id"
--parameters "[{\"name\": \"id\", \"value\": \"1\"}]"
```

다음 명령을 실행하여 이전 SQL 문의 SQL 결과를 가져옵니다.

```
aws redshift-data get-statement-result --id 7529ad05-b905-4d71-9ec6-8b333836eb5a        
```

다음 결과를 제공합니다.

```
{
    "Records": [
        [
            {
                "longValue": 1
            },
            {
                "longValue": 1
            },
            {
                "longValue": 1
            },
            {
                "longValue": 1
            },
            {
                "stringValue": "event 1"
            },
            {
                "stringValue": "2022-02-22 00:00:00.0"
            }
        ]
    ],
    "ColumnMetadata": [
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "eventid",
            "length": 0,
            "name": "eventid",
            "nullable": 0,
            "precision": 10,
            "scale": 0,
            "schemaName": "public",
            "tableName": "event",
            "typeName": "int4"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "venueid",
            "length": 0,
            "name": "venueid",
            "nullable": 0,
            "precision": 5,
            "scale": 0,
            "schemaName": "public",
            "tableName": "event",
            "typeName": "int2"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "catid",
            "length": 0,
            "name": "catid",
            "nullable": 0,
            "precision": 5,
            "scale": 0,
            "schemaName": "public",
            "tableName": "event",
            "typeName": "int2"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "dateid",
            "length": 0,
            "name": "dateid",
            "nullable": 0,
            "precision": 5,
            "scale": 0,
            "schemaName": "public",
            "tableName": "event",
            "typeName": "int2"
        },
        {
            "isCaseSensitive": true,
            "isCurrency": false,
            "isSigned": false,
            "label": "eventname",
            "length": 0,
            "name": "eventname",
            "nullable": 1,
            "precision": 200,
            "scale": 0,
            "schemaName": "public",
            "tableName": "event",
            "typeName": "varchar"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": false,
            "label": "starttime",
            "length": 0,
            "name": "starttime",
            "nullable": 1,
            "precision": 29,
            "scale": 6,
            "schemaName": "public",
            "tableName": "event",
            "typeName": "timestamp"
        }
    ],
    "TotalNumRows": 1
}
```

## 여러 SQL 스테이트먼트 실행
<a name="data-api-calling-cli-batch-execute-statement"></a>

하나의 명령으로 여러 SQL 문을 실행하려면 `aws redshift-data batch-execute-statement` AWS CLI 명령을 사용합니다.

다음 AWS CLI 명령은 클러스터에 대해 3개의 SQL 문을 실행하고 결과를 가져올 식별자를 반환합니다. 이 예에서는 임시 자격 증명 인증 방법을 사용합니다.

```
aws redshift-data batch-execute-statement 
    --db-user myuser 
    --cluster-identifier mycluster-test 
    --database dev 
    --sqls "set timezone to BST" "select * from mytable" "select * from another_table"
```

다음은 이 응답의 예입니다.

```
{
    "ClusterIdentifier": "mycluster-test",
    "CreatedAt": 1598306924.632,
    "Database": "dev",
    "DbUser": "myuser",
    "Id": "d9b6c0c9-0747-4bf4-b142-e8883122f766"
}
```

# SQL 스테이트먼트에 대한 메타데이터 나열
<a name="data-api-calling-cli-list-statements"></a>

SQL 문에 대한 메타데이터를 나열하려면 `aws redshift-data list-statements` AWS CLI 명령을 사용합니다. 이 명령을 실행하기 위한 권한 부여는 호출자의 IAM 권한을 기반으로 합니다.

다음 AWS CLI 명령은 실행된 SQL 문을 나열합니다.

```
aws redshift-data list-statements 
    --status ALL
```

다음은 이 응답의 예입니다.

```
{
    "Statements": [
        {
            "CreatedAt": 1598306924.632,
            "Id": "d9b6c0c9-0747-4bf4-b142-e8883122f766",
            "QueryString": "select * from stl_query limit 1",
            "Status": "FINISHED",
            "UpdatedAt": 1598306926.667
        },
        {
            "CreatedAt": 1598311717.437,
            "Id": "e0ebd578-58b3-46cc-8e52-8163fd7e01aa",
            "QueryString": "select * from stl_query limit 1",
            "Status": "FAILED",
            "UpdatedAt": 1598311719.008
        },
        {
            "CreatedAt": 1598313683.65,
            "Id": "c361d4f7-8c53-4343-8c45-6b2b1166330c",
            "QueryString": "select * from stl_query limit 1",
            "Status": "ABORTED",
            "UpdatedAt": 1598313685.495
        },
        {
            "CreatedAt": 1598306653.333,
            "Id": "a512b7bd-98c7-45d5-985b-a715f3cfde7f",
            "QueryString": "select 1",
            "Status": "FINISHED",
            "UpdatedAt": 1598306653.992
        }
    ]
}
```

# SQL 스테이트먼트에 대한 메타데이터 설명
<a name="data-api-calling-cli-describe-statement"></a>

SQL 문에 대한 메타데이터에 대한 설명을 가져오려면 `aws redshift-data describe-statement` AWS CLI 명령을 사용합니다. 이 명령을 실행하기 위한 권한 부여는 호출자의 IAM 권한을 기반으로 합니다.

다음 AWS CLI 명령은 SQL 문을 설명합니다.

```
aws redshift-data describe-statement 
    --id d9b6c0c9-0747-4bf4-b142-e8883122f766
```

다음은 이 응답의 예입니다.

```
{
    "ClusterIdentifier": "mycluster-test",
    "CreatedAt": 1598306924.632,
    "Duration": 1095981511,
    "Id": "d9b6c0c9-0747-4bf4-b142-e8883122f766",
    "QueryString": "select * from stl_query limit 1",
    "RedshiftPid": 20859,
    "RedshiftQueryId": 48879,
    "ResultRows": 1,
    "ResultSize": 4489,
    "Status": "FINISHED",
    "UpdatedAt": 1598306926.667
}
```

다음은 여러 SQL 문으로 `batch-execute-statement` 명령을 실행한 후 `describe-statement` 응답의 예입니다.

```
{
    "ClusterIdentifier": "mayo",
    "CreatedAt": 1623979777.126,
    "Duration": 6591877,
    "HasResultSet": true,
    "Id": "b2906c76-fa6e-4cdf-8c5f-4de1ff9b7652",
    "RedshiftPid": 31459,
    "RedshiftQueryId": 0,
    "ResultRows": 2,
    "ResultSize": 22,
    "Status": "FINISHED",
    "SubStatements": [
        {
            "CreatedAt": 1623979777.274,
            "Duration": 3396637,
            "HasResultSet": true,
            "Id": "b2906c76-fa6e-4cdf-8c5f-4de1ff9b7652:1",
            "QueryString": "select 1;",
            "RedshiftQueryId": -1,
            "ResultRows": 1,
            "ResultSize": 11,
            "Status": "FINISHED",
            "UpdatedAt": 1623979777.903
        },
        {
            "CreatedAt": 1623979777.274,
            "Duration": 3195240,
            "HasResultSet": true,
            "Id": "b2906c76-fa6e-4cdf-8c5f-4de1ff9b7652:2",
            "QueryString": "select 2;",
            "RedshiftQueryId": -1,
            "ResultRows": 1,
            "ResultSize": 11,
            "Status": "FINISHED",
            "UpdatedAt": 1623979778.076
        }
    ],
    "UpdatedAt": 1623979778.183
}
```

# SQL 스테이트먼트 결과 가져오기
<a name="data-api-calling-cli-get-statement-result"></a>

실행된 SQL 문에서 결과를 가져오려면 `redshift-data get-statement-result` 또는 `redshift-data get-statement-result-v2` AWS CLI 명령을 사용합니다. `get-statement-result`의 결과는 JSON 형식입니다. `get-statement-result-v2`의 결과는 CSV 형식입니다. `execute-statement` 또는 `batch-execute-statement`에 대한 응답으로 수신하는 `Id`를 제공할 수 있습니다. `batch-execute-statement`에 의해 실행된 SQL 문의 `Id` 값은 `describe-statement`의 결과에서 검색할 수 있으며 `b2906c76-fa6e-4cdf-8c5f-4de1ff9b7652:2`와 같이 콜론과 시퀀스 번호가 접미사로 붙습니다. `batch-execute-statement`가 있는 여러 SQL 문을 실행하면 `describe-statement`와 같이 각 SQL 문에 `Id` 값이 있습니다. 이 명령을 실행하기 위한 권한 부여는 호출자의 IAM 권한을 기반으로 합니다.

다음 문은 `ResultFormat`이 `JSON`의 기본값을 갖게 하는 `execute-statement`에 의해 실행되는 SQL 문의 결과를 반환합니다. 결과를 검색하려면 `get-statement-result` 작업을 직접 호출합니다.

```
aws redshift-data get-statement-result 
    --id d9b6c0c9-0747-4bf4-b142-e8883122f766
```

다음 문은 `batch-execute-statement`에 의해 실행되는 두 번째 SQL 문의 결과를 반환합니다.

```
aws redshift-data get-statement-result 
    --id b2906c76-fa6e-4cdf-8c5f-4de1ff9b7652:2
```

다음은 SQL 결과가 응답 키 `Records`의 JSON 형식으로 반환되는 `get-statement-result` 직접 호출에 대한 응답의 예입니다.

```
{
    "ColumnMetadata": [
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "userid",
            "length": 0,
            "name": "userid",
            "nullable": 0,
            "precision": 10,
            "scale": 0,
            "schemaName": "",
            "tableName": "stll_query",
            "typeName": "int4"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "query",
            "length": 0,
            "name": "query",
            "nullable": 0,
            "precision": 10,
            "scale": 0,
            "schemaName": "",
            "tableName": "stll_query",
            "typeName": "int4"
        },
        {
            "isCaseSensitive": true,
            "isCurrency": false,
            "isSigned": false,
            "label": "label",
            "length": 0,
            "name": "label",
            "nullable": 0,
            "precision": 320,
            "scale": 0,
            "schemaName": "",
            "tableName": "stll_query",
            "typeName": "bpchar"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "xid",
            "length": 0,
            "name": "xid",
            "nullable": 0,
            "precision": 19,
            "scale": 0,
            "schemaName": "",
            "tableName": "stll_query",
            "typeName": "int8"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "pid",
            "length": 0,
            "name": "pid",
            "nullable": 0,
            "precision": 10,
            "scale": 0,
            "schemaName": "",
            "tableName": "stll_query",
            "typeName": "int4"
        },
        {
            "isCaseSensitive": true,
            "isCurrency": false,
            "isSigned": false,
            "label": "database",
            "length": 0,
            "name": "database",
            "nullable": 0,
            "precision": 32,
            "scale": 0,
            "schemaName": "",
            "tableName": "stll_query",
            "typeName": "bpchar"
        },
        {
            "isCaseSensitive": true,
            "isCurrency": false,
            "isSigned": false,
            "label": "querytxt",
            "length": 0,
            "name": "querytxt",
            "nullable": 0,
            "precision": 4000,
            "scale": 0,
            "schemaName": "",
            "tableName": "stll_query",
            "typeName": "bpchar"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": false,
            "label": "starttime",
            "length": 0,
            "name": "starttime",
            "nullable": 0,
            "precision": 29,
            "scale": 6,
            "schemaName": "",
            "tableName": "stll_query",
            "typeName": "timestamp"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": false,
            "label": "endtime",
            "length": 0,
            "name": "endtime",
            "nullable": 0,
            "precision": 29,
            "scale": 6,
            "schemaName": "",
            "tableName": "stll_query",
            "type": 93,
            "typeName": "timestamp"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "aborted",
            "length": 0,
            "name": "aborted",
            "nullable": 0,
            "precision": 10,
            "scale": 0,
            "schemaName": "",
            "tableName": "stll_query",
            "typeName": "int4"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "insert_pristine",
            "length": 0,
            "name": "insert_pristine",
            "nullable": 0,
            "precision": 10,
            "scale": 0,
            "schemaName": "",
            "tableName": "stll_query",
            "typeName": "int4"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "concurrency_scaling_status",
            "length": 0,
            "name": "concurrency_scaling_status",
            "nullable": 0,
            "precision": 10,
            "scale": 0,
            "schemaName": "",
            "tableName": "stll_query",
            "typeName": "int4"
        }
    ],
    "Records": [
        [
            {
                "longValue": 1
            },
            {
                "longValue": 3
            },
            {
                "stringValue": "health"
            },
            {
                "longValue": 1023
            },
            {
                "longValue": 15279
            },
            {
                "stringValue": "dev"
            },
            {
                "stringValue": "select system_status from stv_gui_status;"
            },
            {
                "stringValue": "2020-08-21 17:33:51.88712"
            },
            {
                "stringValue": "2020-08-21 17:33:52.974306"
            },
            {
                "longValue": 0
            },
            {
                "longValue": 0
            },
            {
                "longValue": 6
            }
        ]
    ],
    "TotalNumRows": 1
}
```

다음 예시에서는 결과를 JSON으로 반환하기 위해 `execute-statement`로 실행되는 SQL 문을 보여줍니다. 테이블 `testingtable`에는 3개의 정수 열(col1, col2, col3)이 있고, 값(1, 2, 3), (4, 5, 6), (7, 8, 9)이 있는 3개의 행이 있습니다.

```
aws redshift-data execute-statement 
    --database dev 
    --sql "SELECT col1, col2, col3 FROM testingtable" 
    --cluster-id mycluster-test 
    --result-format JSON
```

```
{
    "ClusterIdentifier": "mycluster-test",
    "CreatedAt": "2024-04-02T16:45:25.144000+00:00",
    "Database": "dev",
    "DbUser": "IAMR:Administrator",
    "Id": "d468d942-6df9-4f85-8ae3-bac01a61aec3"
}
```

다음은 SQL 결과가 응답 키 `Records`의 JSON 형식으로 반환되는 `get-statement-result` 직접 호출에 대한 응답의 예입니다.

```
aws redshift-data get-statement-result
    --id d468d942-6df9-4f85-8ae3-bac01a61aec3
```

```
{
    "Records": [
        [
            {
                "longValue": 1
            },
            {
                "longValue": 2
            },
            {
                "longValue": 3
            }
        ],
        [
            {
                "longValue": 4
            },
            {
                "longValue": 5
            },
            {
                "longValue": 6
            }
        ],
        [
            {
                "longValue": 7
            },
            {
                "longValue": 8
            },
            {
                "longValue": 9
            }
        ]
    ],
    "ColumnMetadata": [
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "col1",
            "name": "col1",
            "nullable": 1,
            "precision": 10,
            "scale": 0,
            "schemaName": "public",
            "tableName": "testingtable",
            "typeName": "int4",
            "length": 0
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "col2",
            "name": "col2",
            "nullable": 1,
            "precision": 10,
            "scale": 0,
            "schemaName": "public",
            "tableName": "testingtable",
            "typeName": "int4",
            "length": 0
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "col3",
            "name": "col3",
            "nullable": 1,
            "precision": 10,
            "scale": 0,
            "schemaName": "public",
            "tableName": "testingtable",
            "typeName": "int4",
            "length": 0
        }
    ],
    "TotalNumRows": 3
}
```

다음 예시에서는 결과를 CSV로 반환하기 위해 `execute-statement`로 실행되는 SQL 문을 보여줍니다. 테이블 `testingtable`에는 3개의 정수 열(col1, col2, col3)이 있고, 값(1, 2, 3), (4, 5, 6), (7, 8, 9)이 있는 3개의 행이 있습니다.

```
aws redshift-data execute-statement 
    --database dev 
    --sql "SELECT col1, col2, col3 FROM testingtable" 
    --cluster-id mycluster-test 
    --result-format CSV
```

```
{
    "ClusterIdentifier": "mycluster-test",
    "CreatedAt": "2024-04-02T16:45:25.144000+00:00",
    "Database": "dev",
    "DbUser": "IAMR:Administrator",
    "Id": "d468d942-6df9-4f85-8ae3-bac01a61aec3"
}
```

다음은 SQL 결과가 응답 키 `Records`의 CSV 형식으로 반환되는 `get-statement-result-v2` 직접 호출에 대한 응답의 예입니다. 행은 캐리지 리턴과 줄 바꿈(\$1r\$1n)으로 구분됩니다. `Records`에서 반환되는 첫 번째 행은 열 헤더입니다. CSV 형식으로 반환된 결과는 1MB로 반환되며, 각 청크는 최대 1MB까지 행 수를 저장할 수 있습니다.

```
aws redshift-data get-statement-result-v2
    --id d468d942-6df9-4f85-8ae3-bac01a61aec3
```

```
{
    "Records": [
        {
            "CSVRecords": "col1,col2,col3\r\n1,2,3\r\n4,5,6\r\n7,8,9\r\n"
        }
    ],
    "ColumnMetadata": [
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "col1",
            "name": "col1",
            "nullable": 1,
            "precision": 10,
            "scale": 0,
            "schemaName": "public",
            "tableName": "testingtable",
            "typeName": "int4",
            "length": 0
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "col2",
            "name": "col2",
            "nullable": 1,
            "precision": 10,
            "scale": 0,
            "schemaName": "public",
            "tableName": "testingtable",
            "typeName": "int4",
            "length": 0
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": true,
            "label": "col3",
            "name": "col3",
            "nullable": 1,
            "precision": 10,
            "scale": 0,
            "schemaName": "public",
            "tableName": "testingtable",
            "typeName": "int4",
            "length": 0
        }
    ],
    "TotalNumRows": 3,
    "ResultFormat": "csv"
}
```

# 테이블 설명
<a name="data-api-calling-cli-describe-table"></a>

테이블을 설명하는 메타데이터를 가져오려면 `aws redshift-data describe-table` AWS CLI 명령을 사용합니다.

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하고 테이블을 설명하는 메타데이터를 반환합니다. 이 예에서는 AWS Secrets Manager 인증 방법을 사용합니다.

```
aws redshift-data describe-table  
    --cluster-identifier mycluster-test 
    --database dev 
    --schema information_schema 
    --table sql_features 
    --secret-arn arn:aws:secretsmanager:us-west-2:123456789012:secret:myuser-secret-hKgPWn
```

다음은 이 응답의 예입니다.

```
{
    "ColumnList": [
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": false,
            "length": 2147483647,
            "name": "feature_id",
            "nullable": 1,
            "precision": 2147483647,
            "scale": 0,
            "schemaName": "information_schema",
            "tableName": "sql_features",
            "typeName": "character_data"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": false,
            "length": 2147483647,
            "name": "feature_name",
            "nullable": 1,
            "precision": 2147483647,
            "scale": 0,
            "schemaName": "information_schema",
            "tableName": "sql_features",
            "typeName": "character_data"
        }     
    ]
}
```

다음 AWS CLI 명령은 클러스터에 대해 테이블을 설명하는 SQL 문을 실행합니다. 이 예에서는 임시 자격 증명 인증 방법을 사용합니다.

```
aws redshift-data describe-table 
    --db-user myuser 
    --cluster-identifier mycluster-test 
    --database dev 
    --schema information_schema 
    --table sql_features
```

다음은 이 응답의 예입니다.

```
{
    "ColumnList": [
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": false,
            "length": 2147483647,
            "name": "feature_id",
            "nullable": 1,
            "precision": 2147483647,
            "scale": 0,
            "schemaName": "information_schema",
            "tableName": "sql_features",
            "typeName": "character_data"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": false,
            "length": 2147483647,
            "name": "feature_name",
            "nullable": 1,
            "precision": 2147483647,
            "scale": 0,
            "schemaName": "information_schema",
            "tableName": "sql_features",
            "typeName": "character_data"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": false,
            "length": 2147483647,
            "name": "sub_feature_id",
            "nullable": 1,
            "precision": 2147483647,
            "scale": 0,
            "schemaName": "information_schema",
            "tableName": "sql_features",
            "typeName": "character_data"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": false,
            "length": 2147483647,
            "name": "sub_feature_name",
            "nullable": 1,
            "precision": 2147483647,
            "scale": 0,
            "schemaName": "information_schema",
            "tableName": "sql_features",
            "typeName": "character_data"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": false,
            "length": 2147483647,
            "name": "is_supported",
            "nullable": 1,
            "precision": 2147483647,
            "scale": 0,
            "schemaName": "information_schema",
            "tableName": "sql_features",
            "typeName": "character_data"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": false,
            "length": 2147483647,
            "name": "is_verified_by",
            "nullable": 1,
            "precision": 2147483647,
            "scale": 0,
            "schemaName": "information_schema",
            "tableName": "sql_features",
            "typeName": "character_data"
        },
        {
            "isCaseSensitive": false,
            "isCurrency": false,
            "isSigned": false,
            "length": 2147483647,
            "name": "comments",
            "nullable": 1,
            "precision": 2147483647,
            "scale": 0,
            "schemaName": "information_schema",
            "tableName": "sql_features",
            "typeName": "character_data"
        }
    ]
}
```

# 클러스터의 데이터베이스 나열
<a name="data-api-calling-cli-list-databases"></a>

클러스터의 데이터베이스를 나열하려면 `aws redshift-data list-databases` AWS CLI 명령을 사용합니다.

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하여 데이터베이스를 나열합니다. 이 예에서는 AWS Secrets Manager 인증 방법을 사용합니다.

```
aws redshift-data list-databases  

    --secret-arn arn:aws:secretsmanager:us-west-2:123456789012:secret:myuser-secret-hKgPWn 
    --cluster-identifier mycluster-test 
    --database dev
```

다음은 이 응답의 예입니다.

```
{
    "Databases": [
        "dev"
    ]
}
```

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하여 데이터베이스를 나열합니다. 이 예에서는 임시 자격 증명 인증 방법을 사용합니다.

```
aws redshift-data list-databases  
    --db-user myuser 
    --cluster-identifier mycluster-test 
    --database dev
```

다음은 이 응답의 예입니다.

```
{
    "Databases": [
        "dev"
    ]
}
```

# 데이터베이스의 스키마 나열
<a name="data-api-calling-cli-list-schemas"></a>

데이터베이스의 스키마를 나열하려면 `aws redshift-data list-schemas` AWS CLI 명령을 사용합니다.

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하여 데이터베이스의 스키마를 나열합니다. 이 예에서는 AWS Secrets Manager 인증 방법을 사용합니다.

```
aws redshift-data list-schemas 
    --secret-arn arn:aws:secretsmanager:us-west-2:123456789012:secret:myuser-secret-hKgPWn 
    --cluster-identifier mycluster-test 
    --database dev
```

다음은 이 응답의 예입니다.

```
{
    "Schemas": [
        "information_schema",
        "pg_catalog",
        "pg_internal",
        "public"
    ]
}
```

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하여 데이터베이스의 스키마를 나열합니다. 이 예에서는 임시 자격 증명 인증 방법을 사용합니다.

```
aws redshift-data list-schemas 
    --db-user mysuser 
    --cluster-identifier mycluster-test 
    --database dev
```

다음은 이 응답의 예입니다.

```
{
    "Schemas": [
        "information_schema",
        "pg_catalog",
        "pg_internal",
        "public"
    ]
}
```

# 데이터베이스의 테이블 나열
<a name="data-api-calling-cli-list-tables"></a>

데이터베이스의 테이블을 나열하려면 `aws redshift-data list-tables` AWS CLI 명령을 사용합니다.

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하여 데이터베이스의 테이블을 나열합니다. 이 예에서는 AWS Secrets Manager 인증 방법을 사용합니다.

```
aws redshift-data list-tables 
    --secret-arn arn:aws:secretsmanager:us-west-2:123456789012:secret:myuser-secret-hKgPWn 
    --cluster-identifier mycluster-test 
    --database dev 
    --schema information_schema
```

다음은 이 응답의 예입니다.

```
{
    "Tables": [
        {
            "name": "sql_features",
            "schema": "information_schema",
            "type": "SYSTEM TABLE"
        },
        {
            "name": "sql_implementation_info",
            "schema": "information_schema",
            "type": "SYSTEM TABLE"
        }
}
```

다음 AWS CLI 명령은 클러스터에 대해 SQL 문을 실행하여 데이터베이스의 테이블을 나열합니다. 이 예에서는 임시 자격 증명 인증 방법을 사용합니다.

```
aws redshift-data list-tables  

     --db-user myuser 
     --cluster-identifier mycluster-test 
     --database dev 
     --schema information_schema
```

다음은 이 응답의 예입니다.

```
{
    "Tables": [
        {
            "name": "sql_features",
            "schema": "information_schema",
            "type": "SYSTEM TABLE"
        },
        {
            "name": "sql_implementation_info",
            "schema": "information_schema",
            "type": "SYSTEM TABLE"
        }
    ]
}
```