我正在重新格式化一些旧代码,我有
query = db.engine.execute('SELECT *, ( SELECT min(levenshtein(a, \'{}\''.format(word) + ', 1, 1, 1)) FROM ' +
'regexp_split_to_table(description_unaccent, \' \') as a) as distance FROM '
'"BD_TABLE" ORDER BY distance')
我尝试修改为:
dist = func.levenshtein(BD_TABLE.description_unaccent, data['text'])
query = BD_TABLE.query.filter(dist <= 5).order_by(dist).limit(10)
但是我没有得到距离栏
(SELECT *, ( SELECT min(levenshtein(a,word, 1, 1, 1)) FROM
regexp_split_to_table(description_unaccent,word) as a) as distance)
我读过有关alias和label的内容,但我无法将其作为变量使用,因为后来我想做一些事情:
for row as query:
print(row.distance)