Re: Function to offset current timestamp

From: Dan Harris <fbsd(at)drivefaster(dot)net>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: Function to offset current timestamp
Date: 2007-06-01 17:46:58
Message-ID: 46605B92.1020302@drivefaster.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Dan Harris wrote:
> I'm trying to write a function that can do a select on an integer value
> from a table and subtract that value from current_timestamp.
>
> Let's say I have a table called users and a field called tz_offset..
>
> I want my function to do something like :
>
> select current_timestamp - '( select tz_offset from users where userid =
> ? ) hours'::interval
>
> Obviously this syntax is incorrect, but I'm not quite sure how to do the
> subquery and make the integer result of it part of the quoted interval
> expression.
>
> Any tips?
>
> Thx
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org

ok, sorry to reply to my own message, but I figured out a way:

select current_timestamp - ( select tz_offset from users where userid = ? ) * '1
hour'::interval;

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Steve Crawford 2007-06-01 18:24:45 Re: Function to offset current timestamp
Previous Message Dan Harris 2007-06-01 17:33:58 Function to offset current timestamp