2009-05-08 14 views

答えて

6
create function add_days_to_timestamp(t timestamptz, d int) 
returns timestamptz 
as 
$$ 
begin 
    return t + interval '1' day * d; 
end; 
$$ language 'plpgsql'; 


create operator + (leftarg = timestamptz, rightarg = int, 
     procedure = add_days_to_timestamp); 

さて、これは動作します:

update foo set time = current_timestamp + 3 /* day variable here, 
or a column from your table */ 

注:

を何らかの理由で、これまでの整数を追加すると、内蔵されてPostgresの中で、これは動作します:

select current_timestamp::date + 3 -- but only a date 

これは(あなたがあなた自身のオペレータを定義しない限り、上記参照)ではないでしょう:

select current_timestamp + 3 
+0

ありがとう、これは私がpostgresqlでできることのために本当に目を開けてくれた – egaga

5
select now() + cast('1 day' as interval) * 3 -- example: 3 days 
1

calculatedDateタイムスタンプをタイムゾーンなし。

calculatedDate := current_timestamp + interval '1' day * days_count; 
関連する問題