SQL FTW

One of the things I’ve been helping my Mom with are her finances. I started out with spreadsheets to keep track of things, but about six months ago I switched to using GnuCash, an open-source financial program.

This is a great tool, sometimes a bit more than I need, but sometimes it’s also oddly inadequate: it has all sorts of built-in reports, and they can be customized, but several types of reports are just not available (I am partial to pivot tables). I can export the data I need, but the full export is so complicated as to be almost useless, and the simplified export — they warn about this — doesn’t export certain pieces of data. It was very frustrating.

(For those playing along at home, I was exporting transactions, specifically ones involving expenses, to CSV, and the simplified export would only list one expense split per transaction. Transactions involving multiple splits were thus incomplete.)

I happened to come across some online discussions about GnuCash where people were saving their data into databases rather than the standard file, and were then able to use database tools as well as GNUCash to work with their accounts. Well I like databases too, so…

I decided to use SQLite to make things easier, changed my file format, and opened up the file in DBeaver. The database was a bit convoluted but not crazy, and I tried some SQL snippets I found online to see how it all worked. Then, I wrote a script to export all expenses into a CSV file — it worked like a charm, and I was able to build a pivot table in LibreOffice Calc in like two steps.

The only person who will ever care is me, but I do like to open the spreadsheet occasionally, and just admire it.