

 Amazon Redshift dejará de admitir la creación de nuevas UDF de Python a partir del parche 198. Las UDF de Python existentes seguirán funcionando hasta el 30 de junio de 2026. Para obtener más información, consulte la [publicación del blog](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/). 

# Variables de Amazon Redshift RSQL
<a name="rsql-query-tool-variables"></a>

 Algunas palabras clave actúan como variables en RSQL. Puede establecer cada una en un valor específico o volver a establecer el valor. La mayoría se establecen con `\rset`, que tiene un modo interactivo y otro por lotes. Los comandos se pueden definir en minúsculas o mayúsculas.

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

 Indica el número de filas afectadas por la última solicitud enviada. En el caso de una solicitud de devolución de datos, es el número de filas devueltas a RSQL desde la base de datos. El valor es 0 o un número entero positivo. El valor máximo es 18 446 744 073 709 551 615. 

 La variable `ACTIVITYCOUNT`, que se trata de forma especial, es similar a la variable `ROW_COUNT`. No obstante, `ROW_COUNT` no notifica un recuento de filas afectadas a la aplicación cliente al finalizar el comando para `SELECT`, `COPY` o `UNLOAD`. En cambio, `ACTIVITYCOUNT` sí. 

activitycount\$101.sql:

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

Salida de la consola:

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

views do not exist
```

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

Asigna los niveles de gravedad a los errores. Utilice los niveles de gravedad para determinar un procedimiento a seguir. Si el comando `ERRORLEVEL` no se ha utilizado, su valor es `ON` de manera predeterminada.

errorlevel\$101.sql:

```
\rset errorlevel 42P01 severity 0

select * from tbl;

select 1 as col;

\echo exit
\quit
```

Salida de la consola:

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

col
1

exit
```

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

Permite a los usuarios especificar un encabezado que aparece en la parte superior de un informe. El encabezado que especifica el comando `RSET RTITLE` incluye automáticamente la fecha actual del sistema de la computadora cliente.

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

Salida de la consola:

```
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 un nivel máximo de gravedad de los errores a partir del que RSQL termina el procesamiento de trabajos. Los códigos de devolución son valores enteros que RSQL devuelve al sistema operativo cliente después de completar cada trabajo o tarea. El valor del código de devolución indica el estado de finalización del trabajo o tarea. Si un script contiene una instrucción que produce un nivel de gravedad de error superior al valor de `maxerror` designado, RSQL se cierra inmediatamente. Por lo tanto, para que RSQL se cierre con un nivel de gravedad de error de 8, utilice `RSET MAXERROR 7`.

Contenido de maxerror\$101.sql:

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

\quit
```

Salida de la consola:

```
Maxerror is default.
(1 row)

col
1
```

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

Permite a los usuarios especificar si se aplicará la configuración de los comandos de formato.

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

Salida de la consola:

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

Obtiene el número de registros a los que afecta la consulta anterior. Normalmente se utiliza para comprobar un resultado, como en el siguiente fragmento de código:

```
SET result = ROW_COUNT;

IF result = 0
...
```

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

Este control permite a los usuarios especificar si se imprimirá una línea de caracteres de guion encima de los datos de columna devueltos para las instrucciones SQL.

Ejemplo:

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

Salida de la consola:

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

Establece el formato de salida como ajustado y especifica la anchura de destino de cada línea de un informe. Sin un parámetro, devuelve la configuración actual para el formato y para la anchura de destino.

Contenido de rset\$1width\$101.rsql:

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

Salida de la consola:

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

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

Salida de la consola:

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