How can I generate a series of repeating numbers in PostgreSQL?

后端 未结 7 840
长发绾君心
长发绾君心 2021-01-17 07:36

In PostgreSQL, is it possible to generate a series of repeating numbers? For example, I want to generate the numbers 1 to 10, with each number repeated 3 times:



        
7条回答
  •  遥遥无期
    2021-01-17 08:22

    You could cross join it to a series of 3:

    SELECT a.n
    from generate_series(1, 100) as a(n), generate_series(1, 3)
    

提交回复
热议问题