Install and load
Run these commands in a Haybarn SQL session. The extension is available from the community repository.
INSTALL quackiso FROM community;
LOAD quackiso FROM community;
Using upstream DuckDB? Follow the maintainer’s installation instructions.
Usage example
Bank statements as rows: camt.053, camt.054 and camt.052. A glob is
-- Bank statements as rows: camt.053, camt.054 and camt.052. A glob is
-- parsed in parallel, one worker per file.
SELECT booking_date, amount, currency, credit_debit, counterparty_name
FROM read_iso20022('statements/*.xml', threads := 8)
ORDER BY booking_date;
-- An entry is not always one payment. A batch posts as one <Ntry> holding
-- three <NtryDtls> of one transaction each, and the entry row says so in
-- transaction_count rather than answering with the first one's details.
SELECT e.entry_ref, e.amount AS entry_total, e.transaction_count,
t.end_to_end_id, t.amount, t.creditor_name
FROM read_iso20022('statements/*.xml') e
JOIN read_camt_transactions('statements/*.xml') t
ON t.source_file = e.source_file
AND t.statement_index = e.statement_index
AND t.entry_index = e.entry_index
ORDER BY e.entry_ref, t.entry_details_index, t.transaction_index;
-- An account with no movements is a valid statement, and the balances are
-- all of it. Opening plus the entries signed by their own direction equals
-- closing, exactly, because the amounts are DECIMAL and not floats.
SELECT statement_id, balance_type, balance_type_scheme, amount, currency,
credit_debit, balance_date
FROM read_camt_balances('statements/*.xml')
ORDER BY statement_index, balance_index;
-- What the bank actually applied to a cross-currency entry: the instructed
-- amount, the settled one, and the rate and contract between them.
-- exchange_rate is text, because a rate is not money.
SELECT entry_ref, scope, amount_kind, amount, currency,
exchange_source_currency, exchange_target_currency, exchange_rate
FROM read_camt_amount_details('statements/*.xml')
ORDER BY entry_index, scope, amount_index;
-- Every remittance leaf, not the first one joined by spaces: two invoice
-- numbers in two <Ustrd> are two rows, and slot says which kind each is.
SELECT entry_ref, transaction_index, remittance_index, slot, text
FROM read_camt_remittance('statements/*.xml')
ORDER BY entry_index, transaction_index, remittance_index;
-- What a statement says about itself, one row per statement: its sequence
-- number, the period it covers and the entries and balances the reader
-- found, beside the entry count the bank states. A short statement, a gap
-- and a duplicate are all queries on this one row.
SELECT account_iban, electronic_sequence, from_date, to_date,
summary_entries, entry_count, balance_count
FROM read_camt_statements('statements/*.xml')
ORDER BY account_iban, electronic_sequence;
-- CBPR+ was to stop accepting a fully unstructured postal address on 14
-- November 2026. Swift delayed that release on 27 August 2026 and promised a
-- revised schedule by December 2026. The work stays and the time to measure
-- it grew: of the traffic already on disk, over SWIFT MT and ISO 20022 at
-- once, which parties would be refused once the rule lands, and what is
-- wrong with them.
SELECT family, role, address_format, count(*) AS parties, count(finding) AS refused
FROM audit_addresses('inbox/**/*')
GROUP BY family, role, address_format
ORDER BY refused DESC;
-- The counts say how far a party is from the rule. `address_text` says what
-- there is to work with. A free-text address whose town is already written
-- needs labelling, a bare one needs the data, and neither is the other.
SELECT address_text, address_lines, finding
FROM audit_addresses('inbox/**/*')
WHERE finding IS NOT NULL AND address_text IS NOT NULL
ORDER BY address_lines DESC;
-- What is in the folder, before choosing a reader: one row per file with
-- the message type, the reader that covers it, and the record count.
SELECT family, reader, count(*) AS files, sum(records) AS records
FROM sniff_iso20022('inbox/**/*.xml')
GROUP BY family, reader;
-- SWIFT MT is read the same way, by path: one row per :61: statement line.
-- A `:61:` states no currency of its own, so the statement's balance carries
-- it, along with the account, onto every entry.
SELECT account, value_date, credit_debit, amount,
closing_balance_currency, closing_balance
FROM read_mt940('statements/*.txt')
ORDER BY value_date;
-- MT101 is the FIN original of pain.001, and the grain follows it: one row
-- per transaction, the header carried onto each. The boundary is an exact
-- `:21:`, because `:21R:` and `:21F:` are different fields of the same number.
SELECT sender_reference, tx_ref, ordering_customer, beneficiary, amount,
currency, requested_execution_date
FROM read_mt101('requests/*.txt')
ORDER BY sender_reference, tx_ref;
-- MT104 collects instead of paying, so field 50a is the creditor and 59a the
-- debtor. A settlement sequence states the batch total after the last
-- transaction, and `:19:` is on the wire only when it differs from the sum of
-- them, which is what lets a caller check a batch adds up.
SELECT sender_reference, sum(amount) AS collected,
any_value(sum_of_amounts) AS stated, any_value(settlement_amount) AS settled
FROM read_mt104('collections/*.txt')
GROUP BY sender_reference
ORDER BY sender_reference;
-- Interbank credit transfers (pacs.008, the ISO 20022 MT103).
SELECT uetr, amount, currency, debtor_name, creditor_agent_bic
FROM read_pacs008('pacs008.xml');
-- Credit transfer initiation (pain.001). The payer lives on the <PmtInf>
-- group and is carried down to every transaction in it.
SELECT payment_info_id, debtor_name, creditor_name, amount,
requested_execution_date
FROM read_pain001('pain001.xml');
-- Direct debits (pain.008): the creditor pulls, the mandate makes it legal.
SELECT mandate_id, sequence_type, debtor_name, amount
FROM read_pain008('pain008.xml');
-- Payment returns (pacs.004): what came back, beside what was settled.
-- A return with charges deducted is amount < original_amount.
SELECT return_id, amount, original_amount, return_reason_code,
original_debtor_name, original_creditor_name
FROM read_pacs004('pacs004.xml');
-- Payment status reports (pain.002). A status is stated per batch, per
-- payment group and per transaction, and status_level says which a row is.
SELECT status_level, status, reason_code, original_end_to_end_id, amount
FROM read_pain002('pain002.xml')
WHERE status_level = 'TRANSACTION';
-- Payment status requests (pacs.028): asking where a payment already sent
-- got to. A request states no status of its own, so every monetary column
-- is original_*, and scope says whether the row is one transaction or a
-- whole original message.
SELECT scope, original_msg_id, original_uetr, original_amount,
original_settlement_date
FROM read_pacs028('pacs028.xml');
-- The mandate itself (pain.009), which a direct debit pulls against:
-- who may collect, from whom, how often and up to what.
SELECT mandate_request_id, sequence_type, frequency, creditor_name,
debtor_name, collection_amount
FROM read_pain009('pain009.xml');
-- The investigation family (camt.027 here): the claim that money never
-- arrived. All seven investigation readers share the assignment and case
-- columns, so one case joins across the messages that answer it.
SELECT case_id, case_creator, assigner, assignee, original_amount,
original_settlement_date
FROM read_camt027('camt027.xml');
-- Amounts are DECIMAL(38,5), so totals are exact.
SELECT currency, SUM(amount) AS total
FROM read_iso20022('statements/*.xml')
WHERE credit_debit = 'DBIT'
GROUP BY currency;
Provided by tempoloss. Not yet verified on Haybarn 2.0.0.
Sample data & setupAbout this extension
quackiso reads ISO 20022 and SWIFT MT financial messages directly into DuckDB tables. No Python preprocessing step, no per-schema glue code: point a table function at bank XML or at a folder of MT statements and get transactions as rows.
Forty-three functions: forty readers covering the payment lifecycle end to end, in both directions, a sniffer that routes files to them, an address audit that reads both wire formats at once, and a catalogue that describes every function with an example. Six of the readers cover cash management, one per grain a statement has: the booked entry, the transactions inside a batched one, the balances, the amount blocks with the exchange the bank applied, every remittance text leaf, and the statement header with its sequence number.
Project overview from the community descriptor.
Documentation and resources
Project and build details
- Repository
- tempoloss/quackiso
- License
- MIT
- Maintainers
- tempoloss
- Written in
- Rust
- Build source
686d46679c92- Build definition
- Community descriptor