| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> | 
|---|---|
| To: | "Fernando Papa" <fpapa(at)claxson(dot)com> | 
| Cc: | pgsql-general(at)postgresql(dot)org | 
| Subject: | Re: another problem with pgsql and interva/timestamp | 
| Date: | 2003-03-21 19:30:36 | 
| Message-ID: | 14811.1048275036@sss.pgh.pa.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
"Fernando Papa" <fpapa(at)claxson(dot)com> writes:
> Now, I'm trying to add a numer of days to a date.
> If I do this:
> select now() + interval '2 day'
Do you actually want a datetime result, or just a date?  If the desired
result is a date, you'd find it a lot easier to use the
date-plus-integer operator:
regression=# select current_date;
    date
------------
 2003-03-21
(1 row)
regression=# select current_date + 4;
  ?column?
------------
 2003-03-25
(1 row)
If you do really need sub-day resolution, then stick to timestamp plus
interval.
> I get a datetime two days in the future, thats ok. I want to do this,
> but I have these "2" into a variable inside pl/pgsql.
If you've got a numeric variable, the easiest way to convert it to an
interval is to use the float-times-interval operator:
regression=# select 33 * interval '1 day';
 ?column?
----------
 33 days
(1 row)
regression=# select now() + 33 * interval '1 day';
           ?column?
-------------------------------
 2003-04-23 15:29:12.592024-04
(1 row)
No need to fool with insertion of text into an interval literal ...
regards, tom lane
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2003-03-21 19:37:13 | Re: ERROR: out of free buffers: time to abort! | 
| Previous Message | Tom Lane | 2003-03-21 18:53:36 | Re: 32/64-bit transaction IDs? |