0

考虑 SQLAlchemy 中的以下声明性用户模型:

class User(Base):
    id = Column(Integer, primary_key=True)
    username = Column(String(50), unique=True)
    email = Column(String(1024), unique=True)
    points = Column(Integer, default=0)
    achievements = relationship('Achievement', 
    secondary=achievement_association_table,
    backref='users')
    reviews = relationship('Review', backref='author', lazy='dynamic')
    moderated = Column(Boolean, default=True)

当我执行 aSELECT * FROM user时,我注意到查询没有返回我的所有列,并且只显示了“current_user”列,我只能推测这是使用 Flask-Login 的结果。

进行查询User.query.all()导致以下 SQL:

SELECT "user".created AS user_created, "user".modified AS user_modified, "user".id AS user_id, "user".username AS user_username, "user".email AS user_email, "user".points AS user_points, "user".moderated AS user_moderated

谁能帮我理解为什么这个表是双引号的?我的其他(类似定义的)声明性模型都没有表现出这种行为。

提前致谢!

4

1 回答 1

0

user是保留字,因此需要引用。

有关引用标识符的更多详细信息,请参见手册:
http ://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

于 2013-01-03T16:25:15.617 回答