Python 資料庫入門
Jason Myers
Co-Author of Essential SQLAlchemy and Software Engineer
insert() 陳述式insert() 以要載入資料的資料表為引數values 子句加入要插入的值,格式為 column=value 配對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
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 資料庫入門