Comparing times to "now + 45 seconds"

From: Rikard Bosnjakovic <rikard(dot)bosnjakovic(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Comparing times to "now + 45 seconds"
Date: 2010-01-24 10:08:48
Message-ID: d9e88eaf1001240208u2e73a149j1087baf3d5a417d8@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I have this table:

# select * from live_stats;
times
----------
17:30:00
18:30:00
20:11:00
10:11:00
(4 rows)

I want to compare these times to the actual (current) time + 45
seconds. If the current time + 45 seconds is higher than the time in
the table, I want "true". First, I tried this:

# select times, times > now()::time AS time_compare from live_stats;
times | time_compare
----------+--------------
17:30:00 | t
18:30:00 | t
20:11:00 | t
10:11:00 | f
(4 rows)

Which works, but I don't know how to apply the "45 seconds":

# select times, times > (now()::time + '45 seconds') AS time_compare
from live_stats;
ERROR: operator is not unique: time without time zone + unknown
LINE 1: select times, times > (now()::time + '45 seconds') AS time_c...
^
HINT: Could not choose a best candidate operator. You might need to
add explicit type casts.

# select times, times > (now()::time + '00:00:45') AS time_compare
from live_stats;
ERROR: operator is not unique: time without time zone + unknown
LINE 1: select times, times > (now()::time + '00:00:45') AS time_com...
^
HINT: Could not choose a best candidate operator. You might need to
add explicit type casts.

# select times, times > (now()::time + '00:00:45'::time) AS
time_compare from live_stats;
ERROR: operator is not unique: time without time zone + time without time zone
LINE 1: select times, times > (now()::time + '00:00:45'::time) AS ti...
^
HINT: Could not choose a best candidate operator. You might need to
add explicit type casts.

How am I supposed to do this comparison?

What I'm doing is that I have an application that queries the time and
if 45 seconds have passed, then it's supposed to update the table (to
reduce server load).

--
- Rikard - http://bos.hack.org/cv/

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Jean-Yves F. Barbier 2010-01-24 10:19:03 Re: Comparing times to "now + 45 seconds"
Previous Message Pushpendra Singh Thakur 2010-01-24 10:00:53 Re: optional reference