Amazon Redshift RSQL 변수 - Amazon Redshift

Amazon Redshift RSQL 변수

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

ACTIVITYCOUNT

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

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

activitycount_01.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

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

errorlevel_01.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

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

rset_heading_rtitle_02.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

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

maxerror_01.sql 내용:

\rset maxerror 0 select 1 as col; \quit

콘솔 출력:

Maxerror is default. (1 row) col 1

RFORMAT

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

rset_rformat.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_COUNT

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

SET result = ROW_COUNT; IF result = 0 ...

TITLEDASHES

이 컨트롤을 사용하면 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

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

rset_width_01.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 . . .