pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jason Topaz <topaz@panix.com>
To: Mike C <smith.not.western@gmail.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: SELECT and DATE Function question
Date: Mon, 11 Sep 2006 16:29:32 +0900
Message-ID: <1157959773.2338.5.camel@trane.shiawase.org> (raw)
In-Reply-To: <bd0eabd0609102153h71fd59ffv6d0ca8a78c27fd9c@mail.gmail.com>
References: <bd0eabd0609102153h71fd59ffv6d0ca8a78c27fd9c@mail.gmail.com>

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.





view thread (6+ messages)  latest in thread

Message-ID: <1157959773.2338.5.camel@trane.shiawase.org>
Permalink:  ../1157959773.2338.5.camel@trane.shiawase.org/
Also on:    postgresql.org/message-id/1157959773.2338.5.camel@trane.shiawase.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: topaz@panix.com, smith.not.western@gmail.com
  Subject: Re: SELECT and DATE Function question
  In-Reply-To: <1157959773.2338.5.camel@trane.shiawase.org>
  References: <bd0eabd0609102153h71fd59ffv6d0ca8a78c27fd9c@mail.gmail.com> <1157959773.2338.5.camel@trane.shiawase.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox