Postgresql JSON有密钥

Man*_*oba 9 sql postgresql json postgresql-9.3

我正在努力了解Postgresql处理方式JSON.我已经声明了一个双列表,我想创建一个新的View以获得一些布尔值.

到目前为止,我已经能够将值作为文本获取,但我想得到的是字段是否已定义.例如,如果JSON有键frameMenuData.frameElement,则应打印has_frame为true.

SELECT
  customer_data->>'frameMenuData'->>'frameElement' AS has_frame,
FROM
  simple_list
WHERE
  TRUE
  AND guid='AAAA';
Run Code Online (Sandbox Code Playgroud)

上面的代码给了我那行的内容.我需要知道是否customer_data->>'frameMenuData'->>'frameElement'定义.

我怎么能实现这一目标?

谢谢你的帮助.

Man*_*oba 12

问题解决了.这简直太容易了.

SELECT (customer_data->>'frameMenuData'->>'frameElement' IS NULL) AS has_frame,
Run Code Online (Sandbox Code Playgroud)

  • 我想你只是想要 `customer_data->>'frameMenuData' ?'frameElement' AS has_frame` 请参阅:https://www.postgresql.org/docs/current/functions-json.html 并搜索 (2认同)