Re: Help with syntax for timestamp addition - Mailing list pgsql-general

From Patrick Fiche
Subject Re: Help with syntax for timestamp addition
Date
Msg-id 026701c4d09d$4c139090$2e01a8c0@pc3648pfi
Whole thread Raw
In response to Help with syntax for timestamp addition  (Scott Nixon <snixon@lssi.net>)
Responses Re: Help with syntax for timestamp addition
Re: Help with syntax for timestamp addition
List pgsql-general
Have a try at this syntax

SELECT number
FROM procedures
WHERE date + CAST( numdays || ' days' AS interval ) <= CURRENT_TIMESTAMP;

Patrick

> --------------------------------------------------------------------------
-----------------
> Patrick Fiche
> email : patrick.fiche@aqsacom.com
> tél : 01 69 29 36 18
> --------------------------------------------------------------------------
-----------------
>
>
>


-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org]On Behalf Of Scott Nixon
Sent: lundi 22 novembre 2004 14:56
To: pgsql-general@postgresql.org
Subject: [GENERAL] Help with syntax for timestamp addition


New to Postgres 7.3 from 7.0.

Am having some trouble with a query that worked in 7.0 but not in
7.3.....can't seem to figure out the syntax or find info about how to do
this anywhere.

Consider for the following query:
- 'number' is an integer
- 'procedures' is the table name
- 'date' is a timestamp
- 'numdays' is an integer

SELECT number
FROM procedures
WHERE date + numdays <= CURRENT_TIMESTAMP;

In 7.0 this works with no problem...finding all rows where the date plus
some number of days is less than the current. But in 7.3 I get:

ERROR: Unable to identify an operator '+' for types 'timestamp without
time zone' and 'integer'
You will have to retype this query using an explicit cast


I've never had to create casts before so I'm not too sure how to work
this casting into the query....keep getting various syntax errors no
matter what I try. If I try to incorporate intervals, I also get errors.
I just can't seem to find good examples in any documentation.

Any help is appreciated.

-Scott





---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
      joining column's datatypes do not match




Protected by Polesoft Lockspam
http://www.polesoft.com/refer.html


pgsql-general by date:

Previous
From: Geoffrey
Date:
Subject: Re: How to handle larger databases?
Next
From: Scott Nixon
Date:
Subject: Re: Help with syntax for timestamp addition