2016-01-28 31 views
0

我想ALTER一個表,但它給出以下錯誤:分區表

alter table TABLE_NAME partition by EXTRACT(YEAR FROM to_timestamp(CC)); 

ROLLBACK 2552: Cannot use meta function or non-deterministic function in PARTITION BY expression 

alter table TABLE_NAME partition by date_part('YEAR',to_timestamp(CC)); 

ROLLBACK 2552: Cannot use meta function or non-deterministic function in PARTITION BY expression 

數據在CC列就像

1441650600 

EPOCH時間

有誰知道原因?

+1

可以請您給一些更詳細的信息像你想改變什麼? –

+0

[你看過任何Google搜索結果嗎?](http://bit.ly/1QGipxh) – Kermit

回答

0

如您所知,Vertica基於其行爲將功能分類爲易失性,穩定性和不可變性。更多詳情here

現在,你可以在管理員指南herePARTITION BY子句表達式查詢只能使用不變功能,同時TO_TIMESTAMP() - 你可以檢查here - 僅僅是「穩定」。

0

我個人認爲做這些類型的改變通過執行以下操作簡單: 1.創建一個新的臨時表(與將要進行的更改),反映我想改變 2.然後我複製表所有數據轉移到新表中 3.刪除原始表 4.將新表重命名爲現有名稱。

這是我們在工作中使用的版本控制的一個方面,一切都存儲在Delta腳本中,因此我的代碼的所有更改都完全記錄在案。

至於使用alter語句創建投影,我不能真正評論,但我確實有一個腳本,我覺得會爲你工作,因爲我使用類似的數據格式給你。列被稱爲DateKey,格式爲YYYYMMDD00:

2014020100 

我想按年和季度等我已寫信給分區的以下

CREATE TABLE Schema1.fct_Table1 (
DateKey INT NOT NULL, 
col1 INT NOT NULL, 
col2 INT NOT NULL, 
col3 INT NOT NULL, 
col4 INT NOT NULL, 
col5 INT NOT NULL 
) 
ORDER BY DateKey, col1, col2, col3 
PARTITION BY left(cast(DateKey as char(10)),4) 
     || case 
     when substring(cast(DateKey as char(10)),5,2) in ('01','02','03') then '01' 
     when substring(cast(DateKey as char(10)),5,2) in ('04','05','06') then '02' 
     when substring(cast(DateKey as char(10)),5,2) in ('07','08','09') then '03' 
     when substring(cast(DateKey as char(10)),5,2) in ('10','11','12') then '04' end; 

所以我的劇本是劃分在今年和中當年季度,即 也就是說 月1 - 3 QTR 1 月4 - 6季度2等

我想你可以寫這樣的:

PARTITION BY case 
     when substring(cast(DateKey as char(10)),5,2) = '01' then '01' 
     when substring(cast(DateKey as char(10)),5,2) = '02' then '02'