달나라 노트

Hive : drop table if exists, create temporary table (temporary table 만들고 없애기) 본문

SQL/Apache Hive

Hive : drop table if exists, create temporary table (temporary table 만들고 없애기)

CosmosProject 2020. 12. 17. 01:29
728x90
반응형

 

 

drop table if exists test_temporary_table;
create temporary table test_temporary_table as
select current_date
;

select  *
from test_temporary_table
;
-> 결과 : 2020-12-17

 

 

 

drop table if exists test_temporary_table;

drop table table_name은 어떤 이름의 테이블을 삭제하는데 사용됩니다.

여기에 if exists라는 키워드를 붙이면 해당 테이블이 존재한다면 삭제하고 존재하지않는다면 그냥 넘어가게됩니다.

즉, 존재하지 않는 테이블을 drop하려할 때 생기는 에러를 방지할 수 있죠.

 

 

 

create temporary table test_temporary_table as
select current_date
;

create table table_name as select ~~~~ ;

일반적인 create table은 임시테이블이 아닌 영구 테이블을 생성합니다.

 

그러나 여기에 temporary 라는 키워드를 붙이면 종료 시 알아서 삭제되는 temporary table을 생성할 수 있습니다.

temporary table은 따로 schema 이름을 테이블 앞에 붙이지 않습니다.

 

 

 

 

728x90
반응형
Comments