美好的一天 我正在尝试创建一个带有自动增量列的临时表。我尝试了以下各种版本,但无法正常工作。
create temp table aatemp1 as (id serial, (select unnest (string_to_array('388c45f-998d-4d9c-b59a-bd37b70bba7a', '-'))));
最佳答案
您不能将“静态”列定义和这样的选择结合起来。
您需要分两步完成此操作:
create temp table aatemp1
(
id serial,
some_value text
);
insert into aatemp1(some_value)
select unnest (string_to_array('388c45f-998d-4d9c-b59a-bd37b70bba7a', '-'));
如果你只想在临时表中有一个序号,你也可以这样做:
create temp table aatemp1
as
select row_number() over (order by null) as id,
t.*
from (
select unnest (string_to_array('388c45f-998d-4d9c-b59a-bd37b70bba7a', '-'))
) t;
(但当您插入更多行时不会生成"new"ID)
关于sql - 创建一个带有序列/自动增量列的临时表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22969880/