Re: SELECT and DATE Function question

From: Jason Topaz <topaz(at)panix(dot)com>
To: Mike C <smith(dot)not(dot)western(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: SELECT and DATE Function question
Date: 2006-09-11 07:29:32
Message-ID: 1157959773.2338.5.camel@trane.shiawase.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Mon, 2006-09-11 at 16:53 +1200, Mike C wrote:

> create table blah (start_date timestamp, number_of_days integer);
> insert into blah values (current_timestamp, 25);
> select start_date + number_of_days from blah;
>
> The error I get is:
>
> ERROR: operator does not exist: timestamp without time zone + integer
> HINT: No operator matches the given name and argument type(s). You
> may need to add explicit type casts.
>
> But according to
> http://www.postgresql.org/docs/8.1/static/functions-datetime.html the
> + operator should support integers and treat them as days ( date
> '2001-09-28' + integer '7'). Obviously typing a constant into the
> query is a lot different from using the value of a column, but I would
> have thought it would work.

That's because your data type was "timestamp", not "date". I don't
believe the documentation claims the + operator works on a timestamp and
an integer. But it does claim (correctly) that it works on a date and
an integer. The following example does work:

create table blah (start_date date, number_of_days integer);
insert into blah values (current_date, 25);
select start_date + number_of_days from blah;

Hope that helps a little, at least to explain the apparent disconnect
from the documentation.

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Purusothaman A 2006-09-11 09:15:10 Re: [GENERAL] Problem with lo_export() and lo_import() from remote machine.
Previous Message Mike C 2006-09-11 05:34:03 Re: SELECT and DATE Function question