Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SqlAlchemy中update()子句中的InstrumentedAttribute vs Column_Python_Sqlalchemy - Fatal编程技术网

Python SqlAlchemy中update()子句中的InstrumentedAttribute vs Column

Python SqlAlchemy中update()子句中的InstrumentedAttribute vs Column,python,sqlalchemy,Python,Sqlalchemy,给定一个简单的ORM定义 class User(Base): __tablename__ = 'users' id = sql.Column(sql.Integer, primary_key=True) name = sql.Column(sql.String) 下面两种更新行的方法有什么区别 方法1 connection.execute( User.__table__.update() .where(User.name='Alice') .v

给定一个简单的ORM定义

class User(Base):
    __tablename__ = 'users'

    id = sql.Column(sql.Integer, primary_key=True)
    name = sql.Column(sql.String)
下面两种更新行的方法有什么区别

方法1

connection.execute(
    User.__table__.update()
    .where(User.name='Alice')
    .values(name='Bob')
)
方法2

connection.execute(
    User.__table__.update()
    .where(User.__table__.c.name='Alice')  # <-- Difference
    .values(name='Bob')
)
connection.execute(
用户。\表\更新()

.where(User.u table_u.c.name='Alice')#它们实际上是相同的。