Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.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/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
使用WITH PostgreSQL从相等数组中插入值_Sql_Arrays_Postgresql - Fatal编程技术网

使用WITH PostgreSQL从相等数组中插入值

使用WITH PostgreSQL从相等数组中插入值,sql,arrays,postgresql,Sql,Arrays,Postgresql,我希望smth能够: INSERT INTO Transit (idProc, uuidSeg, number) select * from unnest(array[2, 2]), unnest(array ['3ec172b9-b99f-43e2-83bb-527e9b0fb308', '6a72c69c-1083-4c63-83ec-22b0ab512789']::uuid[]), unnest(array[1, 2]) where 'some_value' IS NOT NULL

我希望smth能够:

INSERT INTO Transit (idProc, uuidSeg, number) 
select * from 
unnest(array[2, 2]), 
unnest(array ['3ec172b9-b99f-43e2-83bb-527e9b0fb308', '6a72c69c-1083-4c63-83ec-22b0ab512789']::uuid[]), 
unnest(array[1, 2]) where 'some_value' IS NOT NULL;
但此查询插入的行太多:

当我运行时,插入正确

WITH data (idProc, uuidSeg, number)  as
    (VALUES
      (2, '3ec172b9-b99f-43e2-83bb-527e9b0fb308'::uuid, 1),
      (2, '6a72c69c-1083-4c63-83ec-22b0ab512789'::uuid, 2))
INSERT INTO Transit (idProc, uuidSeg, number)
SELECT d.idProc, d.uuidSeg, d.number
FROM data d
WHERE 'some_value' is not null;

我的问题是,如何重写我的第一个查询,以便能够同时从数组中正确插入(它们总是相等)?事实上,第一列(idProc)不是数组,它是一个值,必须插入数组长度的倍。有可能吗?

unest()
可以接受多个参数,并行取消对它们的测试:

select *  
from unnest(array[2, 2], 
            array ['3ec172b9-b99f-43e2-83bb-527e9b0fb308', '6a72c69c-1083-4c63-83ec-22b0ab512789']::uuid[], 
            array[1, 2]
           ) u(idProc, uuidSeg, number)
where 'some_value' IS NOT NULL;

其中'some_value'不为空
始终为true:“some_value”是字符串文字。“some_value”是指Python脚本(%s)中的参数值