Vertica的date與timestamp數據類型,to_date()與to_timestamp()函數區別


實驗環境:3節點,RHEL6.4 + Vertica 7.0.1
實驗目的:了解Vertica數據庫的date與timestamp數據類型,to_date()與to_timestamp()函數區別
 
構造的實驗表中只有10條記錄。
1.查詢表記錄數據如下:
irnop=> select start_time from perf_rnc_w_3;
     start_time     
---------------------
2014-05-26 01:00:00
2014-05-26 01:00:00
2014-05-26 01:00:00
2014-05-26 01:00:00
2014-05-26 01:00:00
2014-05-26 01:00:00
2014-05-26 01:00:00
2014-05-26 01:00:00
2014-05-26 01:00:00
2014-05-26 01:00:00
(10 rows)

 

2.實驗過程:
2.1用to_date()查詢5.26號0點~23點間的記錄數,結果不是預期的結果,是0條:
irnop=> select count(*) from perf_rnc_w_3 where start_time >= to_date('2014-05-26 00:00:00','yyyy-MM-dd hh24:mi:ss')
irnop-> and start_time <to_date('2014-05-26 23:00:00','yyyy-MM-dd hh24:mi:ss');
count
-------
     0
(1 row)
irnop=>
2.2用to_timestamp()查詢5.26號0點~23點間的記錄數,結果正確顯示為10條:
irnop=> select count(*) from perf_rnc_w_3 where start_time >= to_timestamp('2014-05-26 00:00:00','yyyy-MM-dd hh24:mi:ss')
irnop-> and start_time <to_timestamp('2014-05-26 23:00:00','yyyy-MM-dd hh24:mi:ss');
count
-------
     10
(1 row)
2.3用to_timestamp()查詢5.26號2點及以后的記錄數,實際是沒有符合條件數據的,結果正確顯示為0條:
irnop=> select count(*) from perf_rnc_w_3 where start_time >= to_timestamp('2014-05-26 02:00:00','yyyy-MM-dd hh24:mi:ss');
count
-------
     0
(1 row)
2.4用to_date()查詢5.26號2點及以后的記錄數,實際是沒有符合條件數據的,但結果此時卻是10條:
irnop=> select count(*) from perf_rnc_w_3 where start_time >= to_date('2014-05-26 02:00:00','yyyy-MM-dd hh24:mi:ss');
count
-------
     10
(1 row)
 
3.總結:
vertica時間類型為date的不精確到小時\分\秒, 
如果需要,定義的時間數據類型必須為timestamp。
同樣,查詢,vertica的to_date()函數不精確到小時\分\秒,
如果需要,需要用to_timestamp()函數。
 
4.延伸:
oracle數據庫的date包括精確到時分秒,所以在oracle—>vertica遷移場景中,建議將oracle的date數據類型修改為vertica的timestamp。
網絡搜索到vertica date和timestamp的數據類型介紹:
DATE 8 Represents a month, day, and year
TIMESTAMP 8 Represents a date and time without timezone
更多vertica數據類型介紹參見:http://www.cnblogs.com/jyzhao/articles/3778948.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM