Hubert 'depesz' Lubaczewski:等待 PostgreSQL 18 - 允许 json{b}_strip_nulls 移除 null 数组元素

💡 原文英文,约300词,阅读约需2分钟。
📝

内容提要

2025年3月5日,Andrew Dunstan 提交补丁,新增参数“strip_in_arrays”,允许 json{b}_strip_nulls 移除 null 数组元素,默认为 false,设为 true 时会移除 null 元素和对象字段。示例展示了该功能的用法。

🎯

关键要点

  • 2025年3月5日,Andrew Dunstan 提交补丁,新增参数 'strip_in_arrays'。
  • 该参数允许 json{b}_strip_nulls 移除 null 数组元素,默认为 false。
  • 当参数设为 true 时,会移除 null 元素和对象字段。
  • 单独的 null 不受影响。
  • 提供了示例展示该功能的用法。
  • 可以移除 json 对象中的 null 元素,文档中有详细说明。
  • 示例中展示了如何使用该功能处理数组和嵌套数组。

延伸问答

什么是 json{b}_strip_nulls 的新参数 'strip_in_arrays'?

'strip_in_arrays' 是一个新增参数,允许在调用 json{b}_strip_nulls 时移除 null 数组元素,默认为 false。

如何使用 'strip_in_arrays' 参数移除 null 元素?

将 'strip_in_arrays' 参数设为 true,可以移除数组中的 null 元素和对象字段。

使用 json{b}_strip_nulls 时,单独的 null 会受到影响吗?

单独的 null 不会受到影响,只有数组中的 null 元素会被移除。

能否给出使用 'strip_in_arrays' 的示例?

例如,使用 jsonb_strip_nulls('[1,2,null,3]', true) 会返回 [1, 2, 3],移除了 null 元素。

这个新功能对嵌套数组有影响吗?

是的,'strip_in_arrays' 参数同样适用于嵌套数组,可以移除其中的 null 元素。

这个补丁的提交日期是什么时候?

该补丁于2025年3月5日提交。

➡️

继续阅读