BQL: filtering on positive/negative amounts

39 views
Skip to first unread message

Stefano Zacchiroli

unread,
Oct 19, 2022, 11:12:11 AM10/19/22
to bean...@googlegroups.com
I'm trying to filter postings based on whether the corresponding amount
is positive or negative, e.g.:

select position where account ~ "^Expenses:Medical" and value(position) > 0;

but this fails with:

error: Operator greater(Amount, int) not supported

(using today's beanquery from git master branch).

I understand an Amount is not an integer, but a (number, currency)
pair. But I don't know how to peak into the number field using BQL.

Any suggestion?
--
Stefano Zacchiroli . za...@upsilon.cc . upsilon.cc/zack _. ^ ._
Full professor of Computer Science o o o \/|V|\/
Télécom Paris, Polytechnic Institute of Paris o o o </> <\>
Co-founder & CTO Software Heritage o o o o /\|^|/\
Former Debian Project Leader & OSI Board Director '" V "'

Daniele Nicolodi

unread,
Oct 19, 2022, 11:18:01 AM10/19/22
to bean...@googlegroups.com
On 19/10/2022 17:12, Stefano Zacchiroli wrote:
> I'm trying to filter postings based on whether the corresponding amount
> is positive or negative, e.g.:
>
> select position where account ~ "^Expenses:Medical" and value(position) > 0;
>
> but this fails with:
>
> error: Operator greater(Amount, int) not supported
>
> (using today's beanquery from git master branch).
>
> I understand an Amount is not an integer, but a (number, currency)
> pair. But I don't know how to peak into the number field using BQL.
>
> Any suggestion?

You can use the number() function to get the number part of an Amount:

SELECT
position
WHERE
account ~ "^Expenses:Medical" AND
number(value(position)) > 0

Cheers,
Dan

Stefano Zacchiroli

unread,
Oct 19, 2022, 1:18:08 PM10/19/22
to bean...@googlegroups.com
On Wed, Oct 19, 2022 at 05:17:57PM +0200, Daniele Nicolodi wrote:
> You can use the number() function to get the number part of an Amount:

Ah, great! I had even looked for that name (more or less randomly) at
https://beancount.github.io/docs/beancount_query_language.html , without
luck. I guess I should've searched the code. Thanks for the help :)
Reply all
Reply to author
Forward
0 new messages