Compare a date and a timestamp with time zone with now() in the same query?
10
votes
1
answer
86965
views
I have multiple database servers I'm querying with a query that compares an expiration column with
now()
. The problem is that one of the servers' expiration column is a timestamp with time zone
, and all the rest are simply date
. I can't change this because I don't have admin access, and in fact I'm only querying the view. Postgres is fairly new to me, so I don't really understand how the dates and times work with each other.
When I try and query the server with timestamp with time zone
by casting the timestamp
as a date
:
...
WHERE
(
status_code = '30000'
OR status_code = '30005'
)
AND CAST(expiration AS DATE) > now()
It works, but using the same query on the servers where expiration
is already a date
fails:
> [Err] ERROR: invalid input syntax for type date: "No End Date"
Any help would be appreciated, I'd really rather not hard code an exception for this one DB server.
Asked by Chris
(205 rep)
Apr 3, 2012, 08:37 PM
Last activity: Nov 21, 2023, 11:30 AM
Last activity: Nov 21, 2023, 11:30 AM