Aadit
Aadit

Reputation: 199

How to truncate seconds from a column (timestamp) in PostgreSQL without using date_trunc function

I am using PostgreSQL 9.3.19, earlier I have made the following Query

SELECT DATE_TRUNC('minute', some_date) FROM some_table;

This was working fine but I got to know that index made on some_date column will be futile because indexes doesn't work with DATE_TRUNC(), Index created was as follows :

CREATE INDEX ON some_table USING BTREE(DATE_TRUNC('minute', some_date));

So is there any other way to truncate seconds without affecting my present Index and without using DATE_TRUNC in PostgreSQL 9.3.19 ?

Upvotes: 1

Views: 4563

Answers (1)

denbon05
denbon05

Reputation: 41

SELECT date_trunc('seconds', '2021-12-28 14:00:03.933438'::timestamp);
-- RESULT 2021-12-28 14:00:03

as here

Upvotes: 3

Related Questions