我想插入多行并用asyncpg取回ID,我找到了两种方法:1:像这样生成sql
INSERT INTO films (code, title, did, date_prod, kind) VALUES
('B6717', 'Tampopo', 110, '1985-02-10', 'Comedy'),
('HG120', 'The Dinner Game', 140, DEFAULT, 'Comedy')
RETURNING id;
2:在for循环中使用准备好的语句
values =(('B6717', 'Tampopo', 110, '1985-02-10', 'Comedy'),
('HG120', 'The Dinner Game', 140, DEFAULT, 'Comedy'))
stmnt = connection.prepare("INSERT INTO films (code, title, did, date_prod, kind) VALUES $1, $2, $3, $4, $5 RETURNING id")
for val in values:
stmnt.fetchval(*val)
如果有 700 000 行的情况下 100 倍,我必须更喜欢哪种方式,或者有什么方法可以结合这种方法?我完全绿色,所以在我身上扔一些西红柿