Re: Date Arithmetic in PL/pgSql

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Lane Van Ingen" <lvaningen(at)esncc(dot)com>
Cc: "John DeSoi" <desoi(at)pgedit(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Date Arithmetic in PL/pgSql
Date: 2005-08-09 01:19:05
Message-ID: 11102.1123550345@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

"Lane Van Ingen" <lvaningen(at)esncc(dot)com> writes:
> My code says:
> select date_trunc('seconds',localtimestamp)::timestamp -
> neighbor_seconds::integer;

> ERROR: operator does not exist: timestamp without time zone - integer

Right. What you need is to use the operators that are there, which
are timestamp minus interval and number times interval:

select date_trunc('seconds',localtimestamp) - neighbor_seconds * '1 second'::interval;

The two casts you did write are both pointless, as the given values were
already of those datatypes.

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Alexander Kotelnikov 2005-08-09 11:49:48 passing column name to a plpgsql function for ALTER TABLE ADD
Previous Message Jason Wong 2005-08-09 00:43:59 Re: Uploading and loading