Re: Date Arithmetic in PL/pgSql - Mailing list pgsql-novice

From Tom Lane
Subject Re: Date Arithmetic in PL/pgSql
Date
Msg-id 11102.1123550345@sss.pgh.pa.us
Whole thread Raw
In response to Re: Date Arithmetic in PL/pgSql  ("Lane Van Ingen" <lvaningen@esncc.com>)
List pgsql-novice
"Lane Van Ingen" <lvaningen@esncc.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

pgsql-novice by date:

Previous
From: Jason Wong
Date:
Subject: Re: Uploading and loading
Next
From: Jim Jarrett
Date:
Subject: Suspend Referential Integrity?