【发布时间】:2015-05-25 15:26:08
【问题描述】:
我正在尝试使用“新”JSONB 类型。
我有一个带有properties jsonb 字段的documents 表,其中有一个字段publication_year。我想查找一年范围内的所有文档记录,例如2013-2015 年。 [编辑:查询一系列值是这里的主要挑战,即使我在下面使用了一个完全匹配的示例。请求的方法也适用于美元范围(价格 > 20 美元和价格
我试过了:
create index test1 on documents using gin ((cast(properties->'announced_on_year' as integer)));
ERROR: cannot cast type jsonb to integer
还有:
create index test1 on documents using gin (cast(properties->>'publication_year' as integer));
ERROR: data type integer has no default operator class for access method "gin"
HINT: You must specify an operator class for the index or define a default operator class for the data type.`
我从这篇帖子http://www.postgresql.org/message-id/10736.1409063604@sss.pgh.pa.us 看到这应该是可能的,但我想不出正确的语法。
当我只是做一个简单的索引时:
create index test1 on documents using gin ((properties->'publication_year'));
创建了一个索引,但我无法使用整数值查询它来获得一个范围,它说
select count(*) from documents where properties->>'publication_year' = 2015;
ERROR: operator does not exist: text = integer
LINE 1: ...*) from documents where properties->>'publication_year' = 2015;
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
高度赞赏任何提示和提示。我相信其他人也会受益。 TIA
【问题讨论】:
标签: postgresql indexing gwt-gin jsonb