Select multiple ids from a PostgreSQL sequence

后端 未结 5 2020
广开言路
广开言路 2021-01-01 11:54

Is there a concise way to select the nextval for a PostgreSQL sequence multiple times in 1 query? This would be the only value being returned.

For example, I would

5条回答
  •  醉梦人生
    2021-01-01 12:12

    My current best solution is:

    SELECT NEXTVAL('mytable_seq') AS id
    UNION ALL
    SELECT NEXTVAL('mytable_seq') AS id
    UNION ALL
    SELECT NEXTVAL('mytable_seq') AS id;
    

    Which will correctly return 3 rows... but I would like something that is minimal SQL for even as much as 100 or more NEXTVAL invocations.

提交回复
热议问题