How come with a query like this:
latest_dates = EquityModel.select(EquityModel.symbol, fn.MAX(EquityModel.date)).where(EquityModel.symbol << symbols).group_by(EquityModel.symbol)
for latest_date in latest_dates.dicts():
print("{:s} - {:d}".format(str(latest_date['date']), latest_date['symbol']))
I get a KeyError
with 'date'
but not with 'symbol'
, given that both are present in EquityModel
?
If I analyse latest_date
in the debugger, it looks like this:
{'date")': datetime.datetime(something), 'symbol': 3}
If I try to access latest_dates['date")']
it works!
What exactly is going on here? Why date
becomes date")
?
Not sure what's going on, you can explicitly assign an alias using: fn.MAX(EquityModel.date).alias('date')
.
Is EquityModel.date a computed field, or is it a normal column?