ERROR: invalid input syntax for type timestamp: "end_time"

ERROR: invalid input syntax for type timestamp: "end_time"

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...
                   ^

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

e->>'end_time'::timestamp 

变成

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