PostgreSQL JSON具有键名

15

我正在尝试理解 Postgresql 如何处理 JSON。我已经声明了一个包含两列的表格,并希望创建一个新视图来获取一些布尔值。

到目前为止,我已经能够以文本形式获取值,但我想要的是获取该字段是否被定义的信息。例如,如果 JSON 具有键 frameMenuData.frameElement,则应将 has_frame 打印为 true。

SELECT
  customer_data->>'frameMenuData'->>'frameElement' AS has_frame,
FROM
  simple_list
WHERE
  TRUE
  AND guid='AAAA';
上面的代码提供了该行的内容。我需要知道是否定义了customer_data->>'frameMenuData'->>'frameElement'
我该如何实现?
感谢您的帮助。
1个回答

17

问题解决了。这并不容易。

SELECT (customer_data->>'frameMenuData'->>'frameElement' IS NULL) AS has_frame,

2
我认为你只是想要 customer_data->>'frameMenuData' ? 'frameElement' AS has_frame,请参考:https://www.postgresql.org/docs/current/functions-json.html 并搜索。 - Marlen T. B.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接