我想创建一个只生成行号的临时表。我没有任何可以拉取数据的源表。
例如,我需要创建一个名为index的列,其中包含1-50行。
发布于 2021-05-25 19:54:58
您可以使用递归CTE:
create table t (id int);
with recursive
x (n) as (
select 1
union all
select n + 1 from x where n < 50
)
insert into t (id)
select n from x;请参阅DB Fiddle上的运行示例。
发布于 2021-05-25 19:51:28
使用generate_series()。但是不要使用名称index,因为这是一个SQL关键字,所以对于列名来说,这是一个非常糟糕的选择:
select gs.i
from generate_series(1, 50, 1) gs(i);https://stackoverflow.com/questions/67687352
复制相似问题