hive creates temporary table

method one

create temporary table 临时表表名 as 
select * from 表名;

The temporary table in hive is only valid for the current session. After the session exits, the table will be automatically deleted.

Note: If the created temporary table name already exists , the current session will use the temporary table you created when applying the table name . Only by deleting or modifying the temporary table can the previously existing table be used .

Temporary tables do not support partitioning fields and creating indexes

Key points to note:

1. If the created temporary table name already exists, then the temporary table is actually used when the current session references the table name. Only drop or rename the temporary table name can use the original table.

2. Temporary table limitations: partition fields and index creation are not supported

Starting from Hive1.1, temporary tables can be stored in memory or SSD, and are configured using the hive.exec.temporary.table.storage parameter. This parameter has three values: memory, ssd, and default.

Method 2

with a1 as (select * from A)
select * from a1;

1.with as is a one-time use and must be used with other sql later! Otherwise, an error will be reported!

2. This must be used as a sql query as a whole, that is, a semicolon cannot be added after the with as statement, otherwise an error will be reported.

Use of multiple with as

with a1 as (select * from A),
a2 as (select * from a1)
select * from a2;


1. Multiple uses of with as must be separated by commas.

2. The temporary table generated by the previous with as can be used in the subsequent with as, but the with clause cannot be nested inside the with clause.
 

Guess you like

Origin blog.csdn.net/eylier/article/details/129152669