

 O Amazon Redshift não permitirá mais a criação de UDFs do Python a partir do Patch 198. As UDFs do Python existentes continuarão a funcionar normalmente até 30 de junho de 2026. Para ter mais informações, consulte a [publicação de blog ](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/). 

# Variáveis do Amazon Redshift RSQL
<a name="rsql-query-tool-variables"></a>

 Algumas palavras-chave funcionam como variáveis no RSQL. Você pode definir cada uma delas para um valor específico ou redefinir o valor. A maioria está definida com `\rset`, que tem um modo interativo e um modo em lote. Os comandos podem ser definidos em minúsculas ou maiúsculas.

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

 Indica o número de linhas afetadas pela última solicitação enviada. Para uma solicitação de retorno de dados, esse é o número de linhas retornadas ao RSQL do banco de dados. O valor é 0 ou um inteiro positivo. O valor máximo é 18.446.744.073.709.551.615. 

 A variável especialmente tratada `ACTIVITYCOUNT` é semelhante à variável `ROW_COUNT`. Porém, `ROW_COUNT` não informa à aplicação cliente a quantidade de linhas afetadas na conclusão do comando para `SELECT`, `COPY` ou `UNLOAD`. Mas `ACTIVITYCOUNT` o faz. 

activitycount\$101.sql:

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

Resultado no console:

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

views do not exist
```

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

Atribui aos erros níveis de gravidade. Use os níveis de gravidade para determinar um curso de ação. Se o comando `ERRORLEVEL` não foi usado, seu valor é `ON` por padrão.

errorlevel\$101.sql:

```
\rset errorlevel 42P01 severity 0

select * from tbl;

select 1 as col;

\echo exit
\quit
```

Resultado no console:

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

col
1

exit
```

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

Permite que os usuários especifiquem um cabeçalho que aparece no início de um relatório. O cabeçalho especificado pelo comando `RSET RTITLE` inclui automaticamente a data atual do sistema do computador cliente.

Conteúdo de 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...
```

Resultado no console:

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

designa um nível máximo de gravidade de erro além do qual o RSQL termina o processamento do trabalho. Os códigos de retorno são valores inteiros que o RSQL retorna ao sistema operacional cliente após a conclusão de cada trabalho ou tarefa. O valor do código de retorno indica o status de conclusão do trabalho ou tarefa. Se um script contiver uma instrução que produza um nível de gravidade de erro maior que o valor `maxerror` designado, o RSQL sai imediatamente. Portanto, para que o RSQL saia em um nível de gravidade de erro 8, use `RSET MAXERROR 7`.

Conteúdo de maxerror\$101.sql:

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

\quit
```

Resultado no console:

```
Maxerror is default.
(1 row)

col
1
```

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

Permite que os usuários especifiquem se as configurações serão aplicadas para os comandos de formatação.

Conteúdo 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...
```

Resultado no console:

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

Obtém o número de registros afetados pela consulta anterior. Geralmente é usado para conferir um resultado, como no seguinte fragmento de código:

```
SET result = ROW_COUNT;

IF result = 0
...
```

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

Esse controle permite que os usuários especifiquem se uma linha de caracteres de traço deve ser impressa acima dos dados de colunas retornados para instruções SQL.

Exemplo:

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

Resultado no console:

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

Define o formato de saída como empacotado e especifica a largura de destino para cada linha em um relatório. Sem um parâmetro, ele retorna as configurações atuais para o formato e a largura do destino.

Conteúdo rset\$1width\$101.rsql:

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

Resultado no console:

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

Exemplo com parâmetro:

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

Resultado no console:

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