Created
November 18, 2023 21:26
-
-
Save alexklibisz/76f7d8c87b8568d692f47b579740cb22 to your computer and use it in GitHub Desktop.
Export Transactions from Firefly-III Database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Export Transactions from Firefly-III Database | |
-- This query produces a reasonable CSV export of transactions from a Firefly-III database. | |
-- Adjust the user_id if you have multiple users. | |
-- Tested on Postgres. | |
select cast(tj.date as date) as date, | |
tj.description as description, | |
round(tcredit.amount, 2) as credit_amount, | |
acredit.name as credit_account, | |
round(tdebit.amount, 2) as debit_amount, | |
adebit.name as debit_account, | |
c.name as category | |
from transactions tcredit | |
join transactions tdebit on tcredit.transaction_journal_id = tdebit.transaction_journal_id | |
join transaction_journals tj on tcredit.transaction_journal_id = tj.id | |
join accounts acredit on tcredit.account_id = acredit.id | |
join accounts adebit on tdebit.account_id = adebit.id | |
join category_transaction_journal ctj on ctj.transaction_journal_id = tj.id | |
join categories c on c.id = ctj.category_id | |
where tcredit.id != tdebit.id and tcredit.amount > 0 | |
and tj.deleted_at is null | |
and tcredit.deleted_at is null | |
and tdebit.deleted_at is null | |
and tj.user_id = 1 | |
order by tj.date, tcredit.transaction_journal_id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment