我正在尝试使用 CTE 将一些随机数据插入表中 -
create table foo (id integer)
with x as (select random())
insert into foo (id)
select x from x
这给出了一个错误:
ERROR: column "id" is of type integer but expression is of type record
只是 CTE 的select
作品:
with x as (select random())
-- insert into foo (id)
select x from x
我也无法打字:
with x as (select random())
insert into foo (id)
select x::integer from x
这给出了一个错误:ERROR: cannot cast type record to integer
。
出了什么问题以及如何解决?
表示选择整行作为列(请注意输出中的括号,而不是纯数字)。就像复合类型的值一样。
例如,
要获取函数的值,您需要访问特定列,而不是整行。
您可以使用插入中的值