proposed new SQL function: ANY_META

92 views
Skip to first unread message

Stefano Zacchiroli

unread,
Nov 14, 2016, 9:38:20 AM11/14/16
to bean...@googlegroups.com
Coming from the Ledger half of the Free accounting world, I'm used to
the fact that transaction metadata propagates down to postings. Please
correct me if I'm wrong, but this doesn't seem to be the case in
Beancount, at least according to my experiments with bean-query.

I'm fine with Beancount model for this. But when querying it is
sometimes handy to have a way to lookup a metadata *first* in a posting,
and then fallback to the parent transaction if the metadata key is not
defined in the posting. Is there a way to implement this in Beancount
SQL language? E.g., is there a boolean (or n-ary) operator that takes
two (or more) values and return the first of them that is not NULL?

Either way, it might be helpful to have a SQL function that will lookup
a metadata key first in a posting and then fallbacks on the parent
transaction. Attached you can find a proposal for such a function,
called ANY_META for lack of better naming ideas.

It works for me, but I'm open to better suggestion on how to
"hierarchically" lookup metadata within transactions.

Cheers.
--
Stefano Zacchiroli . za...@upsilon.cc . upsilon.cc/zack . . o . . . o . o
Computer Science Professor . CTO Software Heritage . . . . . o . . . o o
Former Debian Project Leader . OSI Board Director . . . o o o . . . o .
« the first rule of tautology club is the first rule of tautology club »
0001-add-new-ANY_META-SQL-function-to-query-posting-OR-en.patch

Martin Blais

unread,
Nov 20, 2016, 2:20:00 PM11/20/16
to Beancount

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/20161114143819.ry4mhqp2ermizo3c%40upsilon.cc.
For more options, visit https://groups.google.com/d/optout.

Stefano Zacchiroli

unread,
Nov 20, 2016, 2:40:38 PM11/20/16
to bean...@googlegroups.com
On Sun, Nov 20, 2016 at 02:19:37PM -0500, Martin Blais wrote:
> I like it.
> Done:
> https://bitbucket.org/blais/beancount/commits/90472db4ef144783408844a22cbc5dc4a54ba39b

Thanks Martin!

As a minor nit, can you fix the typo in my family name in the ChangeLog?
(it's single 'l', not two)

TIA,

Martin Blais

unread,
Nov 20, 2016, 3:00:07 PM11/20/16
to Beancount
Fixed. Sorry about that.


--
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+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages