Home:ALL Converter>How to insert multiple values at a time in Auto incremented column using SQLAlchemy

How to insert multiple values at a time in Auto incremented column using SQLAlchemy

Ask Time:2022-11-25T05:33:31         Author:Kirti

Json Formatter

I am using Postgres database and sqlalchemy core. I have below table

CREATE TABLE IF NOT EXISTS id_generation (id SERIAL PRIMARY KEY)

and I am trying to insert multiple values in the id column using below query. number_of_ids can be in multiple of 1000.

for _ in range(number_of_ids):
    conn.execute('INSERT INTO id_generation VALUES (DEFAULT)')

I just want to know is there any other way to write this query using Sqlalchemy core. How we can optimize it ?

Author:Kirti,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/74566383/how-to-insert-multiple-values-at-a-time-in-auto-incremented-column-using-sqlalch
yy