Variabel Amazon Redshift RSQL - Amazon Redshift

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Variabel Amazon Redshift RSQL

Beberapa kata kunci bertindak sebagai variabel dalam RSQL. Anda dapat mengatur masing-masing ke nilai tertentu, atau mengatur ulang nilainya. Sebagian besar diatur dengan\rset, yang memiliki mode interaktif dan mode batch. Perintah dapat didefinisikan dalam huruf kecil atau huruf besar.

ACTIVITYCOUNT

Menunjukkan jumlah baris yang dipengaruhi oleh permintaan terakhir yang dikirimkan. Untuk permintaan pengembalian data, ini adalah jumlah baris yang dikembalikan ke RSQL dari database. Nilai adalah 0 atau bilangan bulat positif. Nilai maksimum adalah 18.446.744.073.709.551.615.

Variabel ACTIVITYCOUNT yang diperlakukan secara khusus mirip dengan variabelROW_COUNT. Namun, ROW_COUNT tidak melaporkan jumlah baris yang terpengaruh ke aplikasi klien pada penyelesaian perintah untukSELECT, COPY atauUNLOAD. Tapi ACTIVITYCOUNT tidak.

activitycount_01.sql:

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

Keluaran konsol:

viewname | schemaname ----------+------------ (0 rows) views do not exist

TINGKAT KESALAHAN

Menugaskan tingkat keparahan untuk kesalahan. Gunakan tingkat keparahan untuk menentukan tindakan. Jika ERRORLEVEL perintah belum digunakan, nilainya secara ON default.

errorlevel_01.sql:

\rset errorlevel 42P01 severity 0 select * from tbl; select 1 as col; \echo exit \quit

Keluaran konsol:

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

HEADING dan RTITLE

Memungkinkan pengguna untuk menentukan header yang muncul di bagian atas laporan. Header yang ditentukan oleh RSET RTITLE perintah secara otomatis menyertakan tanggal sistem saat ini dari komputer klien.

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

Keluaran konsol:

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

Menentukan tingkat keparahan kesalahan maksimum di luar mana RSQL menghentikan pemrosesan pekerjaan. Kode pengembalian adalah nilai integer yang RSQL kembali ke sistem operasi klien setelah menyelesaikan setiap pekerjaan atau tugas. Nilai kode pengembalian menunjukkan status penyelesaian pekerjaan atau tugas. Jika skrip berisi pernyataan yang menghasilkan tingkat keparahan kesalahan lebih besar dari maxerror nilai yang ditentukan, RSQL segera keluar. Oleh karena itu, untuk memiliki RSQL keluar pada tingkat keparahan kesalahan 8, gunakan. RSET MAXERROR 7

konten maxerror_01.sql:

\rset maxerror 0 select 1 as col; \quit

Keluaran konsol:

Maxerror is default. (1 row) col 1

RFORMAT

Memungkinkan pengguna untuk menentukan apakah akan menerapkan pengaturan untuk perintah pemformatan.

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

Keluaran konsol:

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

Mendapat jumlah catatan yang dipengaruhi oleh kueri sebelumnya. Ini biasanya digunakan untuk memeriksa hasil, seperti dalam fragmen kode berikut:

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

TITLEDASHES

Kontrol ini memungkinkan pengguna untuk menentukan apakah garis karakter dasbor akan dicetak di atas data kolom yang dikembalikan untuk pernyataan SQL.

Contoh:

\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;

Keluaran konsol:

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

LEBAR

Menetapkan format output untuk dibungkus dan menentukan lebar target untuk setiap baris dalam laporan. Tanpa parameter, ia mengembalikan pengaturan saat ini untuk format dan lebar target.

konten rset_width_01.rsql:

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

Keluaran konsol:

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

Contoh dengan parameter:

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

Keluaran konsol:

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