Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 在Postgres JSONB字段中仅选择非空键_Sql_Postgresql_Jsonb_Postgres 9.6 - Fatal编程技术网

Sql 在Postgres JSONB字段中仅选择非空键

Sql 在Postgres JSONB字段中仅选择非空键,sql,postgresql,jsonb,postgres-9.6,Sql,Postgresql,Jsonb,Postgres 9.6,我有一个带有JSONB列的Postgres9.6表 > SELECT id, data FROM my_table ORDER BY id LIMIT 4; id | data ----+--------------------------------------- 1 | {"a": [1, 7], "b": null, "c": [8]} 2 | {"a": [2, 9], "b": [1], "c": null} 3 | {"a":

我有一个带有JSONB列的Postgres9.6表

> SELECT id, data FROM my_table ORDER BY id LIMIT 4;

 id |               data    
----+---------------------------------------
  1 | {"a": [1, 7], "b": null, "c": [8]}
  2 | {"a": [2, 9], "b": [1], "c": null}
  3 | {"a": [8, 9], "b": null, "c": [3, 4]}
  4 | {}
如您所见,一些JSON键具有
null

我想排除这些-是否有一种简单的方法可以
仅选择非
null
键值对来生成:

 id |               data    
----+---------------------------------------
  1 | {"a": [1, 7], "c": [8]}
  2 | {"a": [2, 9], "b": [1]}
  3 | {"a": [8, 9], "c": [3, 4]}
  4 | {}

谢谢

您可以使用
jsonb\u strip\u nulls()

在线示例:


请注意,此函数不会删除数组中的
null
值。

请共享您编写的没有生成所需输出的代码
select id, jsonb_strip_nulls(data) as data
from my_table;