I have a column of type varchar which stores date with timestamp, and without timestamp in postgres. While trying to hit the below query,
select * from table where cast(column as date) = CURRENT_DATE::date
it is returning those columns also which has date with timestamp also. How can I modify the query to find the exact match of only dates and not with timestamp.
sample input data:
Column1
2022-12-09 17:38:53.415367
2022-12-09
Expected output:
2022-12-09
Actual: getting both the columns in the result
2022-12-09 17:38:53.415367
2022-12-09
Per my comment:
SELECT
t.dt_val
FROM (
VALUES ('2022-12-09'),
('2022-12-09 17:38:53.415367')) AS t (dt_val)
WHERE
t.dt_val::timestamp = '2022-12-09'::date + '00:00:00'::time;
dt_val
------------
2022-12-09
I used '2022-12-09'::date
instead of current_date
to make the answer relevant in the future. At time of answer current_date
resolves to '2022-12-09'::date
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.