错误:类型为timestamp的输入语法无效:“end_time”

时间:2015-05-15 03:52:58

标签: postgresql postgresql-9.4 jsonb

postgresql的新功能,甚至更新的jsonb。我正在尝试过滤一组对象:

[{"event_slug":"test_1","start_time":"2014-10-08","end_time":"2014-10-12"},
{"event_slug":"test_2","start_time":"2013-06-24","end_time":"2013-07-02"},
{"event_slug":"test_3","start_time":"2014-03-26","end_time":"2014-03-30"}]

我的查询:

SELECT l.*
FROM   locations l
     , jsonb_array_elements(l.events) e
WHERE  l.events @> '{"event_slug":"test_1"}'
AND    e->>'end_time'::timestamp >= '2014-10-30 14:04:06 -0400'::timestamptz;

我收到错误:

ERROR:  invalid input syntax for type timestamp: "end_time"
LINE 5: AND    e->>'end_time'::timestamp >= '2014-10-30 14:04:06 -04...
                   ^

1 个答案:

答案 0 :(得分:2)

这是运算符优先级问题:::->>绑定得更紧密。所以你需要括号。

e->>'end_time'::timestamp 

变为

(e->>'end_time')::timestamp