http://docs.sqlalchemy.org/en/rel_0_8/orm/tutorial.html#counting
uall = User.query.count()
很慢 (subquery的關係?)
session.query(func.count(User.id)).scalar()
快多了
232,053的資料, 用time.time() 算
count(): 4.53022193909 sec
func.count: 0.17828607559 sec
2013年1月3日 星期四
2012年11月19日 星期一
[SQLAlchemy] 不用primary key的table
table沒有設pirmary key會出現這個錯誤:
sqlalchemy.exc.ArgumentError: Mapper Mapper|FooTable|foo_table could not assemble any primary key columns for mapped table 'foo_table'
mapper要設:
"primary_key":(col1, col2)}
sqlalchemy.exc.ArgumentError: Mapper Mapper|FooTable|foo_table could not assemble any primary key columns for mapped table 'foo_table'
mapper要設:
"primary_key":(col1, col2)}
2012年11月14日 星期三
[SQLAlchemy] foreign key constraint 問題
以不delete, SET NULL為例:
1. database level
db.Column(db.Integer, ForeignKey(db.ForeignKey('category.id',ondelete='SET NULL')))
2. pythen level
db.relationship(passive_deletes=True)
訂閱:
文章 (Atom)