SELECT INTO - Amazon Redshift

SELECT INTO

Selecciona las filas definidas por una consulta y las inserta en una nueva tabla. Puede especificar si va a crear una tabla temporal o persistente.

Sintaxis

[ WITH with_subquery [, ...] ] SELECT [ TOP number ] [ ALL | DISTINCT ] * | expression [ AS output_name ] [, ...] INTO [ TEMPORARY | TEMP ] [ TABLE ] new_table [ FROM table_reference [, ...] ] [ WHERE condition ] [ GROUP BY expression [, ...] ] [ HAVING condition [, ...] ] [ { UNION | INTERSECT | { EXCEPT | MINUS } } [ ALL ] query ] [ ORDER BY expression [ ASC | DESC ] [ LIMIT { number | ALL } ] [ OFFSET start ]

Para obtener información acerca de los parámetros de este comando, consulte SELECT.

Ejemplos

Seleccione todas las filas de la tabla EVENT y cree la tabla NEWEVENT:

select * into newevent from event;

Seleccione el resultado de una consulta agregada en una tabla temporal denominada PROFITS:

select username, lastname, sum(pricepaid-commission) as profit into temp table profits from sales, users where sales.sellerid=users.userid group by 1, 2 order by 3 desc;