Vertica数据库临时表

时间:2017-02-01 01:33:53

标签: sql temp-tables vertica

CREATE LOCAL TEMP TABLE DOMAINS_FLAG1 (data1 VARCHAR, data2 VARCHAR,data3 VARCHAR,data4 VARCHAR);
INSERT INTO  DOMAINS_FLAG1
SELECT country,customer,phone_number,count(phone_number) from table1 
where  CAST(create_dt as DATE) = CURRENT_DATE-1
and status='COMPLETED' and ac_tion ='CHARGE' 
GROUP BY country,customer,phone_number;
SELECT * FROM DOMAINS_FLAG1;

我试图创建一个临时表,并使用select语句将一些数据插入到临时表中,但它似乎无效。

结果我可以从下面的截图中看到。 RESULT

  

更新了行数= 0   但是下面的查询给了我169919结果

SELECT country,customer,phone_number,count(phone_number) from table1 
where  CAST(create_dt as DATE) = CURRENT_DATE-1
and status='COMPLETED' and ac_tion ='CHARGE'

2 个答案:

答案 0 :(得分:1)

如何使用create table as

CREATE LOCAL TEMP TABLE DOMAINS_FLAG1 as
SELECT country, customer, phone_number, count(phone_number) as cnt
FROM table1 
WHERE CAST(create_dt as DATE) = CURRENT_DATE-1 AND
      status = 'COMPLETED' AND ac_tion = 'CHARGE' 
GROUP BY country, customer, phone_number;

SELECT * FROM DOMAINS_FLAG1;

答案 1 :(得分:0)

您的连接可能是使用AUTOCOMMIT设置的。

On Commit,默认情况下,临时表会丢失其行。

检查Vertica文档:

您需要在CREATE TABLE语句的末尾添加ON COMMIT PRESERVE ROWS。