有这样一个请求:
self.cursor.execute('''INSERT INTO items (res_id, log_id, link, title, content, n_date, nd_date, s_date, not_date)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)''',
( res_id,
log_id,
str(resource_link),
str(item_title),
str(item_content),
str(n_date),
nd_date,
s_date,
not_date
)
)
我怎样才能让这个查询一次添加一条新闻,而不是一次添加 100 条新闻?
insert我在网上看了这样一个复数的例子:
INSERT INTO MyTable
( Column1, Column2, Column3 )
VALUES
('John', 123, 'Lloyds Office'),
('Jane', 124, 'Lloyds Office'),
('Billy', 125, 'London Office'),
('Miranda', 126, 'Bristol Office');
但在这种情况下,您需要根据需要指定VALUES多次。
使用“executemany()”: