Consider the following table:
Column | Type |
--------------------+--------------------------+
id | bigint |
creation_time | timestamp with time zone |
...
Queries like the following (let alone more complicated JOINs) takes quite a while, because they needs to calculate creation_time::DATE for each item:
SELECT creation_time::DATE, COUNT(*) FROM items GROUP BY 1;
How do I create an index on the day part of the timestamp - creation_time::DATE
?
I have tried:
CREATE INDEX items_day_of_creation_idx ON items (creation_time)::date;
CREATE INDEX items_day_of_creation_idx ON items (creation_time::date);
But both failed with:
ERROR: syntax error at or near "::"
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…