comparing time strings as time in postgres

Viewed 23

I want to basically compare time strings stored as varchar. The test data is:

insert into schedule values (129,'08:30:00','15:45:00','2022-06-22');
insert into schedule values (139,'08:30:00','16:45:00','2022-06-22');
insert into schedule values (149,'08:30:00','17:45:00','2022-06-22');
insert into schedule values (159,'08:30:00','18:45:00','2022-06-22');
insert into schedule values (169,'08:30:00','19:45:00','2022-06-22');
insert into schedule values (179,'08:30:00','20:45:00','2022-06-22');
insert into schedule values (189,'08:30:00','21:30:00','2022-06-22');
insert into schedule values (199,'08:30:00','22:45:00','2022-06-22');  

and this online fiddle executes my query fine: SELECT * FROM schedule where time2::time = '17:45'::time; , but, when I do the query from pg admin it returns empty.

I've also tried using postgres 15 beta, and still the fiddle results are accurate. I basically want to compare something like 07:15:00 to something like 07:16 by casting it to time.

Am I doing it right? And/or perhaps there is a differnt way to achieve the same?

0 Answers
Related