相关疑难解决方法(0)

PostgreSQL:索引时间戳的日期部分

请考虑下表:

       Column       |           Type           |
--------------------+--------------------------+
 id                 | bigint                   |
 creation_time      | timestamp with time zone |
...
Run Code Online (Sandbox Code Playgroud)

像下面这样的查询(更不用说更复杂的JOIN)需要相当长的时间,因为它们需要为每个项计算creation_time :: DATE:

SELECT creation_time::DATE, COUNT(*) FROM items GROUP BY 1;
Run Code Online (Sandbox Code Playgroud)

如何在时间戳的那一天创建索引 - creation_time::DATE

我试过了:

  • CREATE INDEX items_day_of_creation_idx ON items (creation_time)::date;
  • CREATE INDEX items_day_of_creation_idx ON items (creation_time::date);

但都失败了:

ERROR:  syntax error at or near "::"
Run Code Online (Sandbox Code Playgroud)

postgresql indexing date

10
推荐指数
1
解决办法
3332
查看次数

Django 在 Date 上建立 DateTimeField 索引

是否可以仅索引 Django 中 models.DateTimeField 的日期方面?

我似乎无法在文档中找到它,并且我不确定这样做是否有效

class Meta:
    indexes = [
        models.Index(fields=['created_at__year', 'created_at__month', 'created_at__day']),
    ]
Run Code Online (Sandbox Code Playgroud)

django django-models

7
推荐指数
2
解决办法
3098
查看次数

标签 统计

date ×1

django ×1

django-models ×1

indexing ×1

postgresql ×1