Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

postgresql datetrunc too slow

CREATE INDEX ON test (date_trunc('day', updated_at));

/*If updated_at is a timestamp without time zone, that will work fine. 
For a timestamp with time zone, you'll have to specify a time zone, 
because otherwise the result will depend on the session time zone, 
which makes it unusable for an index:*/

CREATE INDEX ON test (date_trunc('day', updated_at AT TIME ZONE 'UTC'));
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #postgresql #datetrunc #slow
ADD COMMENT
Topic
Name
4+6 =