Parameters in Query Directive?

120 views
Skip to first unread message

Henry Mitchell

unread,
May 5, 2025, 4:29:18 PMMay 5
to bean...@googlegroups.com
Hi,

I am tinkering with migrating from ledger to beancount. In bean-query, I see I can run a query defined as a directive in my ledger with ".run query-name". Is there a way to have the query take a parameter and pass it in from beanquery?

As a trivial example, suppose I wanted to pass a number to limit here:
2100-12-31 query "foo" "select date limit %d"

Can I do so? Various attempts at ".run foo 3" seem to fail.

Henry Mitchell

unread,
May 14, 2025, 2:52:31 PMMay 14
to Beancount
Hi,

Are query directives and bean-query not intended to be used this way? Or is this documented somewhere and I failed to find it?

Justus Pendleton

unread,
May 20, 2025, 5:38:34 PMMay 20
to Beancount
No, there is no way to use parameters in queries in that way. It would be a nice thing to add though, so you might check the bean-query project and see if there's already an existing request for something like that and voice your support.

Martin Blais

unread,
May 20, 2025, 7:28:55 PMMay 20
to Beancount
That is indeed a great idea

--
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 beancount+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/beancount/f42bd7db-8b90-4766-917f-3b2f41912223n%40googlegroups.com.

Henry Mitchell

unread,
May 21, 2025, 3:06:49 PMMay 21
to bean...@googlegroups.com
Thanks for confirming this is not supported. I looked through the issues but did not see anything like it so filed https://github.com/beancount/beanquery/issues/249

You received this message because you are subscribed to a topic in the Google Groups "Beancount" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beancount/td18CgN1y-0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beancount+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/beancount/CAK21%2BhMQoT6vOZf7iCm%3DRhH6VpLAZKXrZS%3DbDRNWEMuiGaPJkg%40mail.gmail.com.

Martin Blais

unread,
May 21, 2025, 3:23:01 PMMay 21
to bean...@googlegroups.com

Alexandre Janniaux

unread,
May 21, 2025, 3:51:42 PMMay 21
to bean...@googlegroups.com
As a side note, positional argument feels brittle here since it's not really
a software developement context. I'd suggest this kind of syntax:

```
2100-12-31 query "foo" "select date limit {limit=somedefaultvalue}"
limit: "Number of records to return"
```

and command would be `.run foo limit=3`. Then documentation and reporting
for errors would be much more convenient.
> To view this discussion visit https://groups.google.com/d/msgid/beancount/CAK21%2BhORELLtuROz11rjR33WJL4VDSmMCtiq6s5E6NL-5LS3RQ%40mail.gmail.com.

Alen Šiljak

unread,
May 23, 2025, 4:58:04 PMMay 23
to Beancount
A bit OT but could someone briefly explain what is the purpose of having queries *inside* the journal? Somehow I can't imagine any scenario for this and would appreciate if someone would enlighten me. Perhaps there are some useful use cases.

That said, my general approach is to separate code from data as cleanly as possible/practical. I guess that was one of the points of Plain-Text Accounting, but whatever.

Martin Blais

unread,
May 23, 2025, 5:26:53 PMMay 23
to bean...@googlegroups.com
On Fri, May 23, 2025 at 4:58 PM 'Alen Šiljak' via Beancount <bean...@googlegroups.com> wrote:
A bit OT but could someone briefly explain what is the purpose of having queries *inside* the journal? Somehow I can't imagine any scenario for this and would appreciate if someone would enlighten me. Perhaps there are some useful use cases.

For queries you want to run often, you can just save them in the file and recall them by name.
It's a way to define based named reports in the ledger itself.


That said, my general approach is to separate code from data as cleanly as possible/practical. I guess that was one of the points of Plain-Text Accounting, but whatever.

You can do that too


 
Reply all
Reply to author
Forward
0 new messages