且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在PostgreSQL 9.2中的json字段上创建索引

更新时间:2021-08-20 22:26:45

最适合我案例的解决方案如下:

The solution that works best for my case is the following:

我只是将json视为文本并在文本上创建索引。

I simply treat json as text and create an index on the text.

>> create index on foo ((json::text));

然后必须转换查询,以便它使用索引。

A query would then have to be transformed so that it uses the index.

解释显示是否使用了索引。

Explain reveals whether the index is used or not.

>> explain select * from foo where json::text = 'foo';