How to use a SQL for loop to insert rows into database?

前端 未结 3 623
攒了一身酷
攒了一身酷 2020-12-23 11:22

I\'m using Postgres, and I have a large number of rows that need to be inserted into the database, that differ only in terms of an integer that is incremented. Forgive what

3条回答
  •  别那么骄傲
    2020-12-23 12:11

    Hopefully I've understood what you need (tested on 8.2):

    INSERT INTO articles (id, name)
    SELECT x.id, 'article #' || x.id
      FROM generate_series(1,10000000) AS x(id);
    

提交回复
热议问题