Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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 select子句,其中ID位于json数组中_Postgresql - Fatal编程技术网

Postgresql select子句,其中ID位于json数组中

Postgresql select子句,其中ID位于json数组中,postgresql,Postgresql,我有一个字符串形式的uuidsjson数组,我想在select查询中使用它: SELECT "Animals" WHERE "id" = jsonb_array_elements_text( '["2ffae132-7a46-11eb-8be3-a483e71a4d0b", "2ffae132-7a46-11eb-8be3-a483e71a4d0c", "2ffae132-7a46-11eb-8be

我有一个字符串形式的
uuids
json数组,我想在select查询中使用它:

SELECT "Animals" WHERE "id" = jsonb_array_elements_text(
'["2ffae132-7a46-11eb-8be3-a483e71a4d0b",
  "2ffae132-7a46-11eb-8be3-a483e71a4d0c",
  "2ffae132-7a46-11eb-8be3-a483e71a4d0d"]');
给出了这个错误

ERROR:  set-returning functions are not allowed in WHERE
LINE 1: ...* from "Animals" WHERE "id" = jsonb_arra...
                                                             ^
SQL state: 0A000
Character: 58

为了使用集合返回功能,您需要执行一个子项选择:

edb=# create table animals (id text, name text);
CREATE TABLE
edb=# insert into animals values ('2ffae132-7a46-11eb-8be3-a483e71a4d0b','foo');
INSERT 0 1
edb=# SELECT * from animals WHERE "id" in (select jsonb_array_elements_text(
'["2ffae132-7a46-11eb-8be3-a483e71a4d0b",
  "2ffae132-7a46-11eb-8be3-a483e71a4d0c",
  "2ffae132-7a46-11eb-8be3-a483e71a4d0d"]'));
                  id                  | name 
--------------------------------------+------
 2ffae132-7a46-11eb-8be3-a483e71a4d0b | foo
(1 row)