1

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 ?

5
  • No I am not allowed to change the working Index. I want some other way to truncate seconds @a_horse_with_no_name Commented Aug 30, 2018 at 9:38
  • So if you have the index, what exactly is your question? Commented Aug 30, 2018 at 9:39
  • Read the above question again @a_horse_with_no_name Commented Aug 30, 2018 at 9:42
  • I did, and I don't understand it. What is the problem with the query you have? Does it throw an error? If yes, edit your question and add the exact error message. If it doesn't throw an error but returns the wrong data, then you need to explain what input data you have and what you expect from the query. Commented Aug 30, 2018 at 9:47
  • If it is a performance problem then edit your question and add the execution plan generated using explain (analyze, buffers) as formatted text, no screen shots please Commented Aug 30, 2018 at 9:47

1 Answer 1

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

as here

Sign up to request clarification or add additional context in comments.

1 Comment

It looks like your answer is just what original author of the question was not looking for. Please look at the question again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.