Select multiple ids from a PostgreSQL sequence
问题 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 like to do something really short and sweet like: SELECT NEXTVAL('mytable_seq', 3) AS id; And get: id ----- 118 119 120 (3 rows) 回答1: select nextval('mytable_seq') from generate_series(1,3); generate_series is a function which returns many rows with sequential numbers, configured by it's arguments. In above example, we don't care