How to create index on JSON field in Postgres?

前端 未结 1 937
遥遥无期
遥遥无期 2020-11-28 20:49

In PostgreSQL 9.3 Beta 2 (?), how do I create an index on a JSON field? I tried it using the -> operator used for hstore but got the following e

相关标签:
1条回答
  • 2020-11-28 21:28

    Found:

    CREATE TABLE publishers(id INT, info JSON); 
    CREATE INDEX ON publishers((info->>'name'));
    

    As stated in the comments, the subtle difference here is ->> instead of ->. The former one returns the value as text, the latter as a JSON object.

    0 讨论(0)
提交回复
热议问题