I was able to get the aggregate by passing the resulting rows to
numberify_results, though I really don't understand why that was necessary,
as an API it makes it quite confusing, so maybe I'm still not fully
grasping how beanquery works, but at least I got past that
to put the full example for posterity:
import beanquery
query = '''SELECT sum(position)
WHERE date <= 2024-04-01
AND account ~ "Assets:MyAsset"'''
file_path = "path/to/file.beancount"
connection = beanquery.connect('beancount:' + file_path )
result = connection.execute(query)
rrows = connection.fetchall()
rtypes, rrows = beanquery.numberify.numberify_results(
rtypes, rrows
)
print(rrows[0][0])
I got this idea by perusing Fava code
On Thursday, January 9, 2025 at 8:48:30 PM UTC-8 E wrote:
> Hello,
>
> I'm trying to run queries via automation, but I cannot tell how to use the
> beanquery package
>
> this is what I have
>
> import beanquery
>
> query = '''SELECT sum(position)
> WHERE date <= 2024-04-01
> AND account ~ "Assets:MyAsset"'''
>
> file_path = "path/to/file.beancount"
>
> connection = beanquery.connect('beancount:' + file_path )
> result = connection.execute(query)
> print( result .fetchall())
>
> the problem is that the result contains all the entries that match the
> WHERE clause, but they are not aggregated as I specified in the query
>
> What am I missing?
>
--
You received this message because you are subscribed to the Google Groups
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/beancount/c9f81cc0-064d-4e55-bb66-f8c94d0f05c2n%40googlegroups.com.