beanquery icon indicating copy to clipboard operation
beanquery copied to clipboard

Add "beancount" result set renderer

Open dnicolodi opened this issue 8 months ago • 0 comments

I'm opening this PR mostly to record some thoughts. What it is implemented here is the bare minimum that would be required to make the PRINT statement a special case of SELECT with format set to beancount. This works:

.set format beancount
SELECT entry FROM #postings WHERE date > 2024-01-01

and prints all transactions in the beancount syntax. Actually, all transactions are printed one for every posting they contain. This could be solved with a DISTINCT clause, but entries are not hashable, thus

SELECT DISTINCT entry FROM #postings WHERE date > 2024-01-01

results in an error. This should probably be solved. Entries can be easily make hashable assuming that they are immutable.

However, when selecting for an account, this already does what is expected when filtering for an account:

.set format beancount
SELECT entry FROM #posting WHERE date > 2024-01-01 AND account = 'Assets:Foo'

and may already be useful to solve what @tbm was asking for in #123.

It is more tricky to make this work for tables that do not have a beancount entry type column. The best I can come up with is to use the ROW() construct. For example:

.set format beancount
SELECT ROW(*) FROM #entries WHERE date > 2024-01-01

dnicolodi avatar Jun 16 '24 20:06 dnicolodi