我不太想发表类似于this answer的声明,但是使用Python Sqlalchemy。这是我要编写的代码:
def _update(
self,
table: sqlalchemy.Table,
df: pd.DataFrame,
autocommit: bool = False):
"""
df = pd.DataFrame(columns = ['id', 'values'])
"""
# with new_values(id, values) as (
# values
# ('id1', '{0.1,0.0}'::real[]),
# ('id2', '{0.0,0.1}'::real[])
# )
# update schema.table as t set
# values = new_values.values
# from new_values
# where t.id = new_values.id
stmt = above_comments_to_sqlalchemy(df)
response = self.session.execute(stmt)
if autocommit:
self.session.commit()
return response
答案 0 :(得分:-1)
以下文档:https://docs.sqlalchemy.org/en/13/dialects/postgresql.html
1)使用create_engine()
2)与connect()
3)使用execute()
例如:
engine = create_engine();
connection = engine.connect();
queryString = 'UPDATE <TableName> SET...'
connection.execute(queryString);