Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.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
Postgresql 在postgresesql中迭代json数组并基于数据进行过滤 [{“name”=“abc”,“type”=“charts”},{“name”=“def”,“type”=“transactions”}]_Postgresql - Fatal编程技术网

Postgresql 在postgresesql中迭代json数组并基于数据进行过滤 [{“name”=“abc”,“type”=“charts”},{“name”=“def”,“type”=“transactions”}]

Postgresql 在postgresesql中迭代json数组并基于数据进行过滤 [{“name”=“abc”,“type”=“charts”},{“name”=“def”,“type”=“transactions”}],postgresql,Postgresql,附件列给了我这些数据,但我需要重复这些数据,并检查类型是否存在,以及类型是否=图表或事务。我们主要需要过滤掉它。有人能帮我吗?因为我是Postgres的新手,我不清楚你到底想过滤什么 如果只想查看包含特定类型的行,可以使用: select * from the_table where attachment @> '[{"type": "transactions"}]'; 这将返回数组中至少包含一个{“type”:“transactions”}元素的

附件列给了我这些数据,但我需要重复这些数据,并检查类型是否存在,以及类型是否=图表或事务。我们主要需要过滤掉它。有人能帮我吗?因为我是Postgres的新手,我不清楚你到底想过滤什么

如果只想查看包含特定类型的行,可以使用:

select *
from the_table
where attachment @> '[{"type": "transactions"}]';
这将返回数组中至少包含一个
{“type”:“transactions”}
元素的所有行


这假设您的
附件
列定义为
jsonb
。如果不是,则需要强制转换。

附件
的数据类型是什么?这不是有效的JSON值。