1. 程式人生 > >GreenPlum之生成月份字典表

GreenPlum之生成月份字典表

ast tab map time mon to_char greenplum gre amp

--生成月份字典表
drop table if exists monthmapping;
create table monthmapping as 
select cast(to_char(onday,‘yyyymm‘) as integer) monthid,onday from (
select cast(‘2001-01-01 00:00:00‘ as timestamp) + (c ||‘ day‘)::interval as onday from generate_series(0,10000) as tab(c))tb
where onday<=‘2028-12-31‘
distributed by(monthid,onday);

--當前時間加1年
SELECT now()::timestamp + ‘1 year‘;  

--當前時間加一個月
SELECT now()::timestamp + ‘1 month‘;  

--當前時間加一天
SELECT now()::timestamp + ‘1 day‘;  

--當前時間加一個小時
SELECT now()::timestamp + ‘1 hour‘;  

--當前時間加一分鐘
SELECT now()::timestamp + ‘1 min‘;  

--當前時間加一秒鐘
SELECT now()::timestamp + ‘1 sec‘;  

--當前時間加1年1月1天1時1分1秒
select now()::timestamp + ‘1 year 1 month 1 day 1 hour 1 min 1 sec‘; 
 
--把columnname字段轉換成天然後相加
SELECT now()::timestamp + (columnname || ‘ day‘)::interval FROM tablename

  

GreenPlum之生成月份字典表