Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.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
Arrays Postgres unnest数组语法有问题_Arrays_Postgresql_Insert - Fatal编程技术网

Arrays Postgres unnest数组语法有问题

Arrays Postgres unnest数组语法有问题,arrays,postgresql,insert,Arrays,Postgresql,Insert,我正在寻找关于做这个插入的最佳方法的指导。我试图为role\u id 58385创建11个条目,同时循环遍历每个数组的值。我是PostgreSQL的新手,需要一些关于我在这种情况下做错了什么的指导 INSERT INTO public.acls (role_id, acl_id, update, can_grant, retrieve, create, archive) VALUES ( '58385', unnest(array[1,14,20,2

我正在寻找关于做这个插入的最佳方法的指导。我试图为
role\u id 58385
创建11个条目,同时循环遍历每个数组的值。我是PostgreSQL的新手,需要一些关于我在这种情况下做错了什么的指导

INSERT INTO public.acls (role_id, acl_id, update, can_grant, retrieve, create, archive) VALUES (
           '58385', 
           unnest(array[1,14,20,21,22,24,25,26,36,300,302]), 
           unnest(array[f,f,t,t,f,f,f,t,f,t,t]), 
           unnest(array[f,f,f,f,f,f,f,f,f,f,f]), 
           unnest(array[t,t,t,t,t,t,t,t,t,t,t]), 
           unnest(array[f,f,t,t,f,f,f,t,f,t,t]), 
           unnest(array[f,f,f,f,f,f,f,f,f,f,f])
           )

我是否需要为每个数组设置
SELECT
子查询?或者我可以从六个数组中创建一个数组并插入它们。

一个
选择
就可以了,但是
t
f
必须是
true
false

select '58385',
           unnest(array[1,14,20,21,22,24,25,26,36,300,302]),
           unnest(array[false,false,true,true,false,false,false,true,false,true,true]),
           unnest(array[false,false,false,false,false,false,false,false,false,false,false]),
           unnest(array[true,true,true,true,true,true,true,true,true,true,true]),
           unnest(array[false,false,true,true,false,false,false,true,false,true,true]),
           unnest(array[false,false,false,false,false,false,false,false,false,false,false])
;
 ?column? | unnest | unnest | unnest | unnest | unnest | unnest 
----------+--------+--------+--------+--------+--------+--------
 58385    |      1 | f      | f      | t      | f      | f
 58385    |     14 | f      | f      | t      | f      | f
 58385    |     20 | t      | f      | t      | t      | f
 58385    |     21 | t      | f      | t      | t      | f
 58385    |     22 | f      | f      | t      | f      | f
 58385    |     24 | f      | f      | t      | f      | f
 58385    |     25 | f      | f      | t      | f      | f
 58385    |     26 | t      | f      | t      | t      | f
 58385    |     36 | f      | f      | t      | f      | f
 58385    |    300 | t      | f      | t      | t      | f
 58385    |    302 | t      | f      | t      | t      | f
(11 rows)

我很好奇。为什么这是一个复杂的语法,而不是带有常量值的简单
values()
子句?