Pythonで学ぶデータベース入門
Jason Myers
Co-Author of Essential SQLAlchemy and Software Engineer
insert() 文を使用insert() は挿入先のテーブルを引数に取るvalues 句で 列=値 の組を指定して挿入するfrom sqlalchemy import insert
stmt = insert(employees).values(id=1,name='Jason', salary=1.00, active=True)result_proxy = connection.execute(stmt) print(result_proxy.rowcount)
1
values 句を表す辞書のリストを作成stmt = insert(employees)values_list = [{'id': 2, 'name': 'Rebecca', 'salary': 2.00, 'active': True}, {'id': 3, 'name': 'Bob', 'salary': 0.00, 'active': False}]result_proxy = connection.execute(stmt, values_list)print(result_proxy.rowcount)
2
Pythonで学ぶデータベース入門