Skip site navigation (1) Skip section navigation (2)

Select Interval in plpgsql

From: "Derrick Betts" <derrick(at)grifflink(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Select Interval in plpgsql
Date: 2005-03-22 03:24:21
Message-ID: 017901c52e8e$a5408570$0200a8c0@main (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
I can't seem to figure out how to accomplish this task in a plpgsql function:

I have a timestamp variable 'apt_time' and a varchar variable 'time_offset'.  The time_offset variable usually looks like this: '-2 hours'.  What I want to do is add the time_offset to the timestamp.  So I have tried:

SELECT apt_time + interval time_offset INTO Adjusted_Time;  

Where Adjusted_Time is the variable to store the result.

But I keep getting errors.  I'm not sure where the problem is, as I obviously have not set up the field or variable types properly, or have structured the SELECT improperly.

This statement works just fine:

SELECT apt_time + interval '-2 hours' INTO Adjusted_Time;  

but when I try to use a variable with the interval, I can't get it to work.

Any help would be appreciated.



pgsql-novice by date

Next:From: John DeSoiDate: 2005-03-22 05:52:16
Subject: Re: Select Interval in plpgsql
Previous:From: Morgan KitaDate: 2005-03-22 01:49:16
Subject: Advice on custom data types

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group