Create index on json field in PostgreSQL 9.2

本秂侑毒 提交于 2019-12-04 12:42:21

There is a workaround for this if you feel like installing the PLV8 JavaScript language:

http://people.planetpostgresql.org/andrew/index.php?/archives/249-Using-PLV8-to-index-JSON.html

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

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';

there are no internal index type for JSON or XML type. This fields can hold a values, bat it cannot be indexes - you need to auxiliary columns with hstore columns or similar.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!