Im reformatting some old code, and I have
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')
and I tried to modify to:
dist = func.levenshtein(BD_TABLE.description_unaccent, data['text'])
query = BD_TABLE.query.filter(dist <= 5).order_by(dist).limit(10)
but I'm failing to get the distance column
(SELECT *, ( SELECT min(levenshtein(a,word, 1, 1, 1)) FROM
regexp_split_to_table(description_unaccent,word) as a) as distance)
I read about alias and label, but I couldn't manage to use it after as a variable, because later I wanted to do something as:
for row as query:
print(row.distance)