I have a time with time zone
column, but when the timezones are different the query does not behave has expected.
The table:
CREATE TABLE timezone_table (
id serial NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
"time" time with time zone NOT NULL,
CONSTRAINT timezone_table_pkey PRIMARY KEY (id)
);
Here the insert statement to populate:
insert into timezone_table (id, created_at, updated_at, "time")
values (1, now(), now(), '12:00:00 UTC');
The troublesome query (doesn't find the record as expected):
SELECT * FROM "timezone_table" WHERE "timezone_table"."time" = '08:00:00 -0400';
A query that works as expected (finds the record):
SELECT * FROM "timezone_table" WHERE "timezone_table"."time" = '12:00:00 -0000';
So the question is, why would the troublesome query not return the row as expected when 08:00:00 -0400
is equivalent to 12:00:00 UTC
(or at least I would expect it to be equivalent)?
The weird part is if the troublesome query uses a less-than operator, it finds the row no problem:
SELECT * FROM "timezone_table" WHERE "timezone_table"."time" < '08:00:00 -0400';