3
처음 비어 있지 않은 이름에 대한 쿼리하고
반환 : 나는 acc_username
, us_username
중 첫 번째 비어 있지 않은 값을 검색하고SQLAlchemy의 : COALESCE() 첫째하지 NULL이 아닌 빈 결과
query = session.query(
Account.id.label('acc_id'),
Account.username.label('acc_username'),
User.username.label('us_username'),
User.another_username.label('also_username'),
User.email.label('email')
).join(Account.user)
을 그리고 afterwords을, also_username
및 email
. 이를 위해 나는에서 KeyedTuple
를 생성하는 기능을 준비했습니다 id
먼저 비어 있지 않은 문자열 값을 발견 : (
for q in query.all():
account_tuple = KeyedTuple(
[q.acc_id, q.acc_username or q.us_username or q.also_username or q.email or ''],
labels=_LABELS)
을 대신 차라리 처음 비어 있지 않은 값을 반환 제외 coalesce
의 형태를 사용합니다 파이썬에서 먼저 not False
값) not NULL
대신. 적절한 방법이 있습니까? 나는이 모든 논리를 질의에 맡기고 또 다른 것을 KeyedTuple
을 별도의 기능으로 생성하지 않도록 고맙게 생각한다.