

 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-variables"></a>

 RSQL에서 일부 키워드는 변수로 작동합니다. 각각을 특정 값으로 설정하거나 값을 재설정할 수 있습니다. 대부분은 대화형 모드와 배치 모드가 있는 `\rset`에 의해 설정됩니다. 소문자나 대문자로 명령을 정의할 수 있습니다.

## ACTIVITYCOUNT
<a name="rsql-query-tool-activitycount"></a>

 마지막으로 제출된 요청의 영향을 받는 행 수를 나타냅니다. 데이터 반환 요청의 경우 데이터베이스에서 RSQL로 반환되는 행 수입니다. 값은 0 또는 양의 정수입니다. 최댓값은 18,446,744,073,709,551,615입니다.

 특수 처리되는 변수 `ACTIVITYCOUNT`는 `ROW_COUNT` 변수와 비슷합니다. 하지만 `ROW_COUNT`는 `SELECT`, `COPY` 또는 `UNLOAD`에 대한 명령 완료 시 영향을 받는 행 수를 클라이언트 애플리케이션에 보고하지 않습니다. 하지만 `ACTIVITYCOUNT`는 보고합니다.

activitycount\$101.sql:

```
select viewname, schemaname
from pg_views
where schemaname = 'not_existing_schema';
\if :ACTIVITYCOUNT = 0
\remark 'views do not exist'
\endif
```

콘솔 출력:

```
viewname | schemaname
----------+------------
(0 rows)

views do not exist
```

## ERRORLEVEL
<a name="rsql-query-tool-describe-rset-errorlevel"></a>

오류에 심각도 수준을 할당합니다. 심각도 수준에 따라 일련의 조치를 결정할 수 있습니다. `ERRORLEVEL` 명령을 사용하지 않은 경우 해당 값은 기본적으로 `ON`입니다.

errorlevel\$101.sql:

```
\rset errorlevel 42P01 severity 0

select * from tbl;

select 1 as col;

\echo exit
\quit
```

콘솔 출력:

```
Errorlevel is on.
rsql: ERROR: relation "tbl" does not exist
(1 row)

col
1

exit
```

## HEADING 및 RTITLE
<a name="rsql-query-tool-describe-rset-heading-rtitle"></a>

보고서 상단에 표시되는 헤더를 지정할 수 있습니다. `RSET RTITLE` 명령에서 지정한 헤더에는 클라이언트 컴퓨터의 현재 시스템 날짜를 자동으로 포함됩니다.

rset\$1heading\$1rtitle\$102.rsql 내용:

```
\remark Starting...
\rset rtitle "Marketing Department||Confidential//Third Quarter//Chicago"
\rset width 70
\rset rformat on
select * from rsql_test.tbl_currency order by id limit 2;
\exit
\remark Finishing...
```

콘솔 출력:

```
Starting...
Rtitle is set to: &DATE||Marketing Department||Confidential//Third Quarter//Chicago (Changes will take effect after RFORMAT is
switched ON)
Target width is 70.
Rformat is on.
09/11/20       Marketing       Department Confidential
                  Third Quarter
                     Chicago
id  | bankid  | name |      start_date
100 |       1 | USD | 2020-09-11 10:51:39.106905
110 |       1 | EUR | 2020-09-11 10:51:39.106905
(2 rows)

Press any key to continue . . .
```

## MAXERROR
<a name="rsql-query-tool-describe-rset-maxerror"></a>

RSQL이 해당 수준을 넘으면 작업 처리를 종료하는 최대 오류 심각도 수준을 지정합니다. 반환 코드는 각 작업 또는 태스크를 완료한 후 RSQL이 클라이언트 운영 체제에 반환하는 정수 값입니다. 반환 코드 값은 작업 또는 태스크의 완료 상태를 나타냅니다. 지정된 `maxerror` 값보다 큰 오류 심각도 수준을 생성하는 문이 스크립트에 포함된 경우 RSQL이 즉시 종료됩니다. 따라서 오류 심각도 수준 8에서 RSQL가 종료되도록 하려면 `RSET MAXERROR 7`을 사용합니다.

maxerror\$101.sql 내용:

```
\rset maxerror 0
                        
select 1 as col;

\quit
```

콘솔 출력:

```
Maxerror is default.
(1 row)

col
1
```

## RFORMAT
<a name="rsql-query-tool-describe-rset-heading-rformat"></a>

형식 지정 명령에 대한 설정을 적용할지 여부를 지정할 수 있습니다.

rset\$1rformat.rsql 내용:

```
\remark Starting...
\pset border 2
\pset format wrapped
\pset expanded on
\pset title 'Great Title'
select * from rsql_test.tbl_long where id = 500;
\rset rformat
select * from rsql_test.tbl_long where id = 500;
\rset rformat off
select * from rsql_test.tbl_long where id = 500;
\rset rformat on
select * from rsql_test.tbl_long where id = 500;
\exit
\remark Finishing...
```

콘솔 출력:

```
Starting...
Border style is 2. (Changes will take effect after RFORMAT is switched ON)
Output format is wrapped. (Changes will take effect after RFORMAT is switched ON)
Expanded display is on. (Changes will take effect after RFORMAT is switched ON)
Title is "Great Title". (Changes will take effect after RFORMAT is switched ON)
id  |                                                             long_string
500 | In general, the higher the number the more borders and lines the tables will have, but details depend on the particular
format.
(1 row)

Rformat is on.
Great Title
+-[ RECORD 1 ]+----------------------------------------------------------------------------------------------------------------------
-----------+
| id           | 500
|
| long_string | In general, the higher the number the more borders and lines the tables will have, but details depend on the
particular format. |
+-------------+----------------------------------------------------------------------------------------------------------------------
-----------+

Rformat is off.
id  |                                                             long_string
500 | In general, the higher the number the more borders and lines the tables will have, but details depend on the particular format.
(1 row)

Rformat is on.
Great Title
+-[ RECORD 1 ]+----------------------------------------------------------------------------------------------------------------------
-----------+
| id           | 500
|
| long_string | In general, the higher the number the more borders and lines the tables will have, but details depend on the
particular format. |
+-------------+----------------------------------------------------------------------------------------------------------------------
-----------+
Press any key to continue . . .
```

## ROW\$1COUNT
<a name="rsql-query-tool-describe-rset-row_count"></a>

이전 쿼리의 영향을 받는 레코드 수를 가져옵니다. 일반적으로 다음 코드 조각에서처럼 결과를 확인하는 데 사용됩니다.

```
SET result = ROW_COUNT;

IF result = 0
...
```

## TITLEDASHES
<a name="rsql-query-tool-describe-rset-heading-titledashes"></a>

이 컨트롤을 사용하면 SQL 문에 대해 반환된 열 데이터 위에 대시 문자 행을 인쇄할지 여부를 지정할 수 있습니다.

예제:

```
\rset titledashes on
select dept_no, emp_no, salary from rsql_test.EMPLOYEE
where dept_no = 100;
\rset titledashes off
select dept_no, emp_no, salary from rsql_test.EMPLOYEE
where dept_no = 100;
```

콘솔 출력:

```
dept_no      emp_no          salary
----------- ----------- --------------------
100         1000346        1300.00
100         1000245        5000.00
100         1000262        2450.00

dept_no     emp_no         salary
100         1000346        1300.00
100         1000245        5000.00
100         1000262        2450.00
```

## WIDTH
<a name="rsql-query-tool-describe-rset-heading-width"></a>

보고서의 출력 형식을 래핑으로 설정하고 각 행의 대상 너비를 지정합니다. 파라미터를 지정하지 않으면 형식과 대상 너비 모두 현재 설정이 반환됩니다.

rset\$1width\$101.rsql 내용:

```
\echo Starting...
\rset width
\rset width 50
\rset width
\quit
\echo Finishing...
```

콘솔 출력:

```
Starting...
Target width is 75.
Target width is 50.
Target width is 50.
Press any key to continue . . .
```

파라미터를 사용하는 예:

```
\echo Starting...
\rset rformat on
\pset format wrapped
select * from rsql_test.tbl_long where id = 500;
\rset width 50
select * from rsql_test.tbl_long where id = 500;
\quit
\echo Finishing...
```

콘솔 출력:

```
Starting...
Rformat is on.
Output format is wrapped.
id  |                                          long_string
500 | In general, the higher the number the more borders and lines the ta.
    |.bles will have, but details depend on the particular format.
(1 row)

Target width is 50.
id  |                                          long_string
500 | In general, the higher the number the more.
    |. borders and lines the tables will have, b.
    |.ut details depend on the particular format.
    |..
(1 row)
Press any key to continue . . .
```