【发布时间】:2016-07-21 17:16:59
【问题描述】:
我有一个列address,在表Houses 中输入jsonb[],其中包含一个看起来像这样的数组:
"{
"{\"zip\": \"13203-1807\",
\"city\": \"\SYRACUSE\",
\"state\": \"NEW YORK\",
\"street\": \"\999 PROSPECT AVENUE\"}"
}"
我正在尝试查询地址城市为“雪城”的所有房屋;到目前为止我有:
SELECT * FROM Houses WHERE address -> 'city' = 'SYRACUSE'
并收到此错误:
No operator matches the given name and argument type(s). You might need to add explicit type casts.
我查看了PG Official Documentation on JSON Functions and Operators 以及几个 StackOverflow 的答案都无济于事。
【问题讨论】:
-
您的列类型是
jsonb还是jsonb[]?->运算符将与前者一起使用,但后者是一个 postgresql 数组,需要数组运算符。 -
jsonb[]@jmelesky -
出于好奇,为什么? JSON 已经可以保存数组,所以我不清楚为什么要在 JSON 对象的 JSON 数组上存储 JSON 对象的 postgresql 数组。
-
没有理由。可以更轻松地查询 JSON 对象的 JSON 数组吗?
标签: sql arrays json postgresql postgresql-9.5