gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-exchange] branch master updated: migration to new amount style fo


From: gnunet
Subject: [taler-exchange] branch master updated: migration to new amount style for exchangedb
Date: Sat, 29 Jul 2023 23:01:19 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new e47e5c0c migration to new amount style for exchangedb
e47e5c0c is described below

commit e47e5c0cfba7746263775e8bbd4064b640f69020
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat Jul 29 23:01:06 2023 +0200

    migration to new amount style for exchangedb
---
 src/exchangedb/0002-aggregation_transient.sql      |    5 +-
 src/exchangedb/0002-aml_history.sql                |    5 +-
 src/exchangedb/0002-aml_status.sql                 |    5 +-
 src/exchangedb/0002-close_requests.sql             |    8 +-
 src/exchangedb/0002-denominations.sql              |   15 +-
 src/exchangedb/0002-deposits.sql                   |    3 +-
 src/exchangedb/0002-global_fee.sql                 |    9 +-
 src/exchangedb/0002-history_requests.sql           |    5 +-
 src/exchangedb/0002-known_coins.sql                |    5 +-
 src/exchangedb/0002-partners.sql                   |    5 +-
 src/exchangedb/0002-policy_details.sql             |   22 +-
 src/exchangedb/0002-profit_drains.sql              |    5 +-
 src/exchangedb/0002-purse_deposits.sql             |    5 +-
 src/exchangedb/0002-purse_requests.sql             |   15 +-
 src/exchangedb/0002-recoup.sql                     |    3 +-
 src/exchangedb/0002-recoup_refresh.sql             |    3 +-
 src/exchangedb/0002-refresh_commitments.sql        |    3 +-
 src/exchangedb/0002-refunds.sql                    |    3 +-
 src/exchangedb/0002-reserves_close.sql             |    6 +-
 src/exchangedb/0002-reserves_in.sql                |    5 +-
 src/exchangedb/0002-reserves_open_deposits.sql     |    3 +-
 src/exchangedb/0002-reserves_open_requests.sql     |    5 +-
 src/exchangedb/0002-reserves_out.sql               |    3 +-
 src/exchangedb/0002-wad_in_entries.sql             |   15 +-
 src/exchangedb/0002-wad_out_entries.sql            |   15 +-
 src/exchangedb/0002-wads_in.sql                    |    5 +-
 src/exchangedb/0002-wads_out.sql                   |    5 +-
 src/exchangedb/0002-wire_fee.sql                   |    6 +-
 src/exchangedb/0002-wire_out.sql                   |    5 +-
 src/exchangedb/exchange_do_batch_coin_known.sql    |   34 +-
 .../exchange_do_batch_reserves_update.sql          |   16 +-
 .../exchange_do_batch_withdraw_insert.sql          |    7 +-
 src/exchangedb/exchange_do_deposit.sql             |   25 +-
 src/exchangedb/exchange_do_expire_purse.sql        |   17 +-
 src/exchangedb/exchange_do_history_request.sql     |    7 +-
 src/exchangedb/exchange_do_insert_aml_decision.sql |   20 +-
 ...exchange_do_insert_or_update_policy_details.sql |   92 +-
 src/exchangedb/exchange_do_melt.sql                |   26 +-
 src/exchangedb/exchange_do_purse_delete.sql        |   13 +-
 src/exchangedb/exchange_do_purse_deposit.sql       |   59 +-
 src/exchangedb/exchange_do_purse_merge.sql         |   36 +-
 src/exchangedb/exchange_do_recoup_by_reserve.sql   |   11 +-
 src/exchangedb/exchange_do_recoup_to_coin.sql      |   39 +-
 src/exchangedb/exchange_do_recoup_to_reserve.sql   |   24 +-
 src/exchangedb/exchange_do_refund.sql              |   74 +-
 src/exchangedb/exchange_do_refund_by_coin.sql      |   20 +-
 .../exchange_do_reserve_open_deposit.sql           |   27 +-
 src/exchangedb/exchange_do_reserves_in_insert.sql  |   45 +-
 src/exchangedb/exchange_do_withdraw.sql            |    7 +-
 src/exchangedb/pg_add_denomination_key.c           |   34 +-
 src/exchangedb/pg_add_policy_fulfillment_proof.c   |   15 +-
 src/exchangedb/pg_aggregate.c                      |   31 +-
 src/exchangedb/pg_create_aggregation_transient.c   |   10 +-
 src/exchangedb/pg_do_deposit.c                     |    5 +-
 src/exchangedb/pg_do_melt.c                        |    6 +-
 src/exchangedb/pg_do_refund.c                      |   15 +-
 src/exchangedb/pg_ensure_coin_known.c              |   15 +-
 src/exchangedb/pg_find_aggregation_transient.c     |    5 +-
 src/exchangedb/pg_get_coin_transactions.c          |   42 +-
 src/exchangedb/pg_get_denomination_info.c          |   20 +-
 src/exchangedb/pg_get_drain_profit.c               |    4 +-
 src/exchangedb/pg_get_global_fee.c                 |   11 +-
 src/exchangedb/pg_get_global_fees.c                |   11 +-
 src/exchangedb/pg_get_melt.c                       |   12 +-
 src/exchangedb/pg_get_purse_deposit.c              |    3 +-
 src/exchangedb/pg_get_purse_request.c              |    7 +-
 src/exchangedb/pg_get_reserve_history.c            |  162 +-
 src/exchangedb/pg_get_unfinished_close_requests.c  |    3 +-
 src/exchangedb/pg_get_wire_fee.c                   |    8 +-
 src/exchangedb/pg_get_wire_fees.c                  |    7 +-
 src/exchangedb/pg_get_withdraw_info.c              |   10 +-
 src/exchangedb/pg_have_deposit2.c                  |    9 +-
 src/exchangedb/pg_helper.h                         |   15 +-
 src/exchangedb/pg_insert_aml_decision.c            |    5 +-
 src/exchangedb/pg_insert_close_request.c           |   14 +-
 src/exchangedb/pg_insert_denomination_info.c       |   32 +-
 src/exchangedb/pg_insert_deposit.c                 |   11 +-
 src/exchangedb/pg_insert_drain_profit.c            |   11 +-
 src/exchangedb/pg_insert_global_fee.c              |   20 +-
 src/exchangedb/pg_insert_partner.c                 |    8 +-
 src/exchangedb/pg_insert_purse_request.c           |   14 +-
 src/exchangedb/pg_insert_records_by_table.c        |  329 +--
 src/exchangedb/pg_insert_refund.c                  |    9 +-
 src/exchangedb/pg_insert_reserve_closed.c          |   15 +-
 src/exchangedb/pg_insert_reserve_open_deposit.c    |    5 +-
 src/exchangedb/pg_insert_wire_fee.c                |   15 +-
 src/exchangedb/pg_iterate_denomination_info.c      |   16 +-
 src/exchangedb/pg_iterate_denominations.c          |   18 +-
 src/exchangedb/pg_iterate_reserve_close_info.c     |    3 +-
 src/exchangedb/pg_lookup_denomination_key.c        |   15 +-
 src/exchangedb/pg_lookup_global_fee_by_time.c      |    9 +-
 src/exchangedb/pg_lookup_records_by_table.c        |  114 +-
 src/exchangedb/pg_lookup_transfer_by_deposit.c     |   12 +-
 src/exchangedb/pg_lookup_wire_fee_by_time.c        |    6 +-
 src/exchangedb/pg_lookup_wire_transfer.c           |    6 +-
 src/exchangedb/pg_persist_policy_details.c         |   17 +-
 src/exchangedb/pg_profit_drains_get_pending.c      |    3 +-
 .../pg_select_account_merges_above_serial_id.c     |    6 +-
 .../pg_select_aggregation_amounts_for_kyc_check.c  |    3 +-
 src/exchangedb/pg_select_aggregation_transient.c   |    3 +-
 src/exchangedb/pg_select_aml_history.c             |    3 +-
 src/exchangedb/pg_select_aml_process.c             |    6 +-
 src/exchangedb/pg_select_aml_threshold.c           |    3 +-
 .../pg_select_deposits_above_serial_id.c           |    3 +-
 src/exchangedb/pg_select_deposits_missing_wire.c   |    3 +-
 .../pg_select_history_requests_above_serial_id.c   |    3 +-
 .../pg_select_merge_amounts_for_kyc_check.c        |    3 +-
 src/exchangedb/pg_select_purse.c                   |    6 +-
 src/exchangedb/pg_select_purse_by_merge_pub.c      |    8 +-
 .../pg_select_purse_decisions_above_serial_id.c    |    3 +-
 .../pg_select_purse_deposits_above_serial_id.c     |    9 +-
 src/exchangedb/pg_select_purse_deposits_by_purse.c |    3 +-
 .../pg_select_purse_merges_above_serial_id.c       |    6 +-
 .../pg_select_purse_requests_above_serial_id.c     |    3 +-
 src/exchangedb/pg_select_recoup_above_serial_id.c  |    3 +-
 .../pg_select_recoup_refresh_above_serial_id.c     |    3 +-
 .../pg_select_refreshes_above_serial_id.c          |    6 +-
 src/exchangedb/pg_select_refunds_above_serial_id.c |   13 +-
 src/exchangedb/pg_select_refunds_by_coin.c         |   44 +-
 .../pg_select_reserve_closed_above_serial_id.c     |    6 +-
 .../pg_select_reserve_open_above_serial_id.c       |    3 +-
 .../pg_select_reserves_in_above_serial_id.c        |    5 +-
 ...select_reserves_in_above_serial_id_by_account.c |    6 +-
 .../pg_select_wire_out_above_serial_id.c           |    3 +-
 ...pg_select_wire_out_above_serial_id_by_account.c |    4 +-
 .../pg_select_withdraw_amounts_for_kyc_check.c     |    6 +-
 .../pg_select_withdrawals_above_serial_id.c        |    6 +-
 src/exchangedb/pg_set_purse_balance.c              |    6 +-
 src/exchangedb/pg_store_wire_transfer_out.c        |   10 +-
 src/exchangedb/pg_trigger_aml_process.c            |   11 +-
 src/exchangedb/pg_update_aggregation_transient.c   |   14 +-
 src/exchangedb/shard-0001.sql                      | 2575 --------------------
 132 files changed, 914 insertions(+), 3847 deletions(-)

diff --git a/src/exchangedb/0002-aggregation_transient.sql 
b/src/exchangedb/0002-aggregation_transient.sql
index 2d77e63c..851342d8 100644
--- a/src/exchangedb/0002-aggregation_transient.sql
+++ b/src/exchangedb/0002-aggregation_transient.sql
@@ -25,8 +25,7 @@ DECLARE
 BEGIN
   PERFORM create_partitioned_table(
     'CREATE TABLE %I '
-    '(amount_val INT8 NOT NULL'
-    ',amount_frac INT4 NOT NULL'
+    '(amount taler_amount NOT NULL'
     ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
     ',merchant_pub BYTEA CHECK (LENGTH(merchant_pub)=32)'
     ',exchange_account_section TEXT NOT NULL'
@@ -44,7 +43,7 @@ BEGIN
   );
   PERFORM comment_partitioned_column(
        'Sum of all of the aggregated deposits (without deposit fees)'
-      ,'amount_val'
+      ,'amount'
       ,table_name
       ,shard_suffix
   );
diff --git a/src/exchangedb/0002-aml_history.sql 
b/src/exchangedb/0002-aml_history.sql
index 1768b97d..18b79bae 100644
--- a/src/exchangedb/0002-aml_history.sql
+++ b/src/exchangedb/0002-aml_history.sql
@@ -27,8 +27,7 @@ BEGIN
     'CREATE TABLE IF NOT EXISTS %I'
       '(aml_history_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
       ',h_payto BYTEA CHECK (LENGTH(h_payto)=32)'
-      ',new_threshold_val INT8 NOT NULL DEFAULT(0)'
-      ',new_threshold_frac INT4 NOT NULL DEFAULT(0)'
+      ',new_threshold taler_amount NOT NULL DEFAULT(0,0)'
       ',new_status INT4 NOT NULL DEFAULT(0)'
       ',decision_time INT8 NOT NULL DEFAULT(0)'
       ',justification VARCHAR NOT NULL'
@@ -54,7 +53,7 @@ BEGIN
   );
   PERFORM comment_partitioned_column(
      'new monthly inbound transaction limit below which we are OK'
-    ,'new_threshold_val'
+    ,'new_threshold'
     ,table_name
     ,partition_suffix
   );
diff --git a/src/exchangedb/0002-aml_status.sql 
b/src/exchangedb/0002-aml_status.sql
index f7b7e83b..47e8d90c 100644
--- a/src/exchangedb/0002-aml_status.sql
+++ b/src/exchangedb/0002-aml_status.sql
@@ -27,8 +27,7 @@ BEGIN
     'CREATE TABLE IF NOT EXISTS %I'
       '(aml_status_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
       ',h_payto BYTEA PRIMARY KEY CHECK (LENGTH(h_payto)=32)'
-      ',threshold_val INT8 NOT NULL DEFAULT(0)'
-      ',threshold_frac INT4 NOT NULL DEFAULT(0)'
+      ',threshold taler_amount NOT NULL DEFAULT(0,0)'
       ',status INT4 NOT NULL DEFAULT(0)'
       ',kyc_requirement INT8 NOT NULL DEFAULT(0)'
     ') %s ;'
@@ -49,7 +48,7 @@ BEGIN
   );
   PERFORM comment_partitioned_column(
      'monthly inbound transaction limit below which we are OK (if status is 1)'
-    ,'threshold_val'
+    ,'threshold'
     ,table_name
     ,partition_suffix
   );
diff --git a/src/exchangedb/0002-close_requests.sql 
b/src/exchangedb/0002-close_requests.sql
index 32149b1b..a1e7fe38 100644
--- a/src/exchangedb/0002-close_requests.sql
+++ b/src/exchangedb/0002-close_requests.sql
@@ -29,10 +29,8 @@ BEGIN
       ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)'
       ',close_timestamp INT8 NOT NULL'
       ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
-      ',close_val INT8 NOT NULL'
-      ',close_frac INT4 NOT NULL'
-      ',close_fee_val INT8 NOT NULL'
-      ',close_fee_frac INT4 NOT NULL'
+      ',close taler_amount NOT NULL'
+      ',close_fee taler_amount NOT NULL'
       ',payto_uri VARCHAR NOT NULL'
       ',done BOOL NOT NULL DEFAULT(FALSE)'
       ',PRIMARY KEY (reserve_pub,close_timestamp)'
@@ -60,7 +58,7 @@ BEGIN
   );
   PERFORM comment_partitioned_column(
      'Balance of the reserve at the time of closing, to be wired to the 
associated bank account (minus the closing fee)'
-    ,'close_val'
+    ,'close'
     ,table_name
     ,partition_suffix
   );
diff --git a/src/exchangedb/0002-denominations.sql 
b/src/exchangedb/0002-denominations.sql
index d468a387..a3de2b14 100644
--- a/src/exchangedb/0002-denominations.sql
+++ b/src/exchangedb/0002-denominations.sql
@@ -25,16 +25,11 @@ CREATE TABLE denominations
   ,expire_withdraw INT8 NOT NULL
   ,expire_deposit INT8 NOT NULL
   ,expire_legal INT8 NOT NULL
-  ,coin_val INT8 NOT NULL
-  ,coin_frac INT4 NOT NULL
-  ,fee_withdraw_val INT8 NOT NULL
-  ,fee_withdraw_frac INT4 NOT NULL
-  ,fee_deposit_val INT8 NOT NULL
-  ,fee_deposit_frac INT4 NOT NULL
-  ,fee_refresh_val INT8 NOT NULL
-  ,fee_refresh_frac INT4 NOT NULL
-  ,fee_refund_val INT8 NOT NULL
-  ,fee_refund_frac INT4 NOT NULL
+  ,coin taler_amount NOT NULL
+  ,fee_withdraw taler_amount NOT NULL
+  ,fee_deposit taler_amount NOT NULL
+  ,fee_refresh taler_amount NOT NULL
+  ,fee_refund taler_amount NOT NULL
   );
 COMMENT ON TABLE denominations
   IS 'Main denominations table. All the valid denominations the exchange knows 
about.';
diff --git a/src/exchangedb/0002-deposits.sql b/src/exchangedb/0002-deposits.sql
index d8afdac8..43c8d9ea 100644
--- a/src/exchangedb/0002-deposits.sql
+++ b/src/exchangedb/0002-deposits.sql
@@ -29,8 +29,7 @@ BEGIN
       ',shard INT8 NOT NULL'
       ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
       ',known_coin_id INT8 NOT NULL' -- FIXME: column needed!?
-      ',amount_with_fee_val INT8 NOT NULL'
-      ',amount_with_fee_frac INT4 NOT NULL'
+      ',amount_with_fee taler_amount NOT NULL'
       ',wallet_timestamp INT8 NOT NULL'
       ',exchange_timestamp INT8 NOT NULL'
       ',refund_deadline INT8 NOT NULL'
diff --git a/src/exchangedb/0002-global_fee.sql 
b/src/exchangedb/0002-global_fee.sql
index 0a2f9b49..f6526798 100644
--- a/src/exchangedb/0002-global_fee.sql
+++ b/src/exchangedb/0002-global_fee.sql
@@ -18,12 +18,9 @@ CREATE TABLE global_fee
   (global_fee_serial BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
   ,start_date INT8 NOT NULL
   ,end_date INT8 NOT NULL
-  ,history_fee_val INT8 NOT NULL
-  ,history_fee_frac INT4 NOT NULL
-  ,account_fee_val INT8 NOT NULL
-  ,account_fee_frac INT4 NOT NULL
-  ,purse_fee_val INT8 NOT NULL
-  ,purse_fee_frac INT4 NOT NULL
+  ,history_fee taler_amount NOT NULL
+  ,account_fee taler_amount NOT NULL
+  ,purse_fee taler_amount NOT NULL
   ,purse_timeout INT8 NOT NULL
   ,history_expiration INT8 NOT NULL
   ,purse_account_limit INT4 NOT NULL
diff --git a/src/exchangedb/0002-history_requests.sql 
b/src/exchangedb/0002-history_requests.sql
index 853a435d..2694a7ce 100644
--- a/src/exchangedb/0002-history_requests.sql
+++ b/src/exchangedb/0002-history_requests.sql
@@ -30,8 +30,7 @@ BEGIN
       ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)'
       ',request_timestamp INT8 NOT NULL'
       ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
-      ',history_fee_val INT8 NOT NULL'
-      ',history_fee_frac INT4 NOT NULL'
+      ',history_fee taler_amount NOT NULL'
       ',PRIMARY KEY (reserve_pub,request_timestamp)'
     ') %s ;'
     ,table_name
@@ -57,7 +56,7 @@ BEGIN
   );
   PERFORM comment_partitioned_column(
      'History fee approved by the signature'
-    ,'history_fee_val'
+    ,'history_fee'
     ,table_name
     ,shard_suffix
   );
diff --git a/src/exchangedb/0002-known_coins.sql 
b/src/exchangedb/0002-known_coins.sql
index 4cdb974e..c8cc888f 100644
--- a/src/exchangedb/0002-known_coins.sql
+++ b/src/exchangedb/0002-known_coins.sql
@@ -31,8 +31,7 @@ BEGIN
       ',coin_pub BYTEA NOT NULL PRIMARY KEY CHECK (LENGTH(coin_pub)=32)'
       ',age_commitment_hash BYTEA CHECK (LENGTH(age_commitment_hash)=32)'
       ',denom_sig BYTEA NOT NULL'
-      ',remaining_val INT8 NOT NULL DEFAULT(0)'
-      ',remaining_frac INT4 NOT NULL DEFAULT(0)'
+      ',remaining taler_amount NOT NULL DEFAULT(0,0)'
     ') %s ;'
     ,table_name
     ,'PARTITION BY HASH (coin_pub)'
@@ -57,7 +56,7 @@ BEGIN
   );
   PERFORM comment_partitioned_column(
      'Value of the coin that remains to be spent'
-    ,'remaining_val'
+    ,'remaining'
     ,table_name
     ,partition_suffix
   );
diff --git a/src/exchangedb/0002-partners.sql b/src/exchangedb/0002-partners.sql
index c80f2d74..ed09378d 100644
--- a/src/exchangedb/0002-partners.sql
+++ b/src/exchangedb/0002-partners.sql
@@ -21,8 +21,7 @@ CREATE TABLE partners
   ,end_date INT8 NOT NULL
   ,next_wad INT8 NOT NULL DEFAULT (0)
   ,wad_frequency INT8 NOT NULL
-  ,wad_fee_val INT8 NOT NULL
-  ,wad_fee_frac INT4 NOT NULL
+  ,wad_fee taler_amount NOT NULL
   ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
   ,partner_base_url TEXT NOT NULL
   ,PRIMARY KEY (partner_master_pub, start_date)
@@ -39,7 +38,7 @@ COMMENT ON COLUMN partners.next_wad
   IS 'at what time should we do the next wad transfer to this partner 
(frequently updated); set to forever after the end_date';
 COMMENT ON COLUMN partners.wad_frequency
   IS 'how often do we promise to do wad transfers';
-COMMENT ON COLUMN partners.wad_fee_val
+COMMENT ON COLUMN partners.wad_fee
   IS 'how high is the fee for a wallet to be added to a wad to this partner';
 COMMENT ON COLUMN partners.partner_base_url
   IS 'base URL of the REST API for this partner';
diff --git a/src/exchangedb/0002-policy_details.sql 
b/src/exchangedb/0002-policy_details.sql
index c9bfd157..8c53b0dc 100644
--- a/src/exchangedb/0002-policy_details.sql
+++ b/src/exchangedb/0002-policy_details.sql
@@ -21,15 +21,11 @@ CREATE TABLE policy_details
   ,policy_hash_code BYTEA PRIMARY KEY CHECK(LENGTH(policy_hash_code)=16)
   ,policy_json VARCHAR
   ,deadline INT8 NOT NULL
-  ,commitment_val INT8 NOT NULL
-  ,commitment_frac INT4 NOT NULL
-  ,accumulated_total_val INT8 NOT NULL
-  ,accumulated_total_frac INT4 NOT NULL
-  ,fee_val INT8 NOT NULL
-  ,fee_frac INT4 NOT NULL
-  ,transferable_val INT8 NOT NULL
-  ,transferable_frac INT8 NOT NULL
-  ,fulfillment_state smallint NOT NULL CHECK(fulfillment_state between 0 and 5)
+  ,commitment taler_amount NOT NULL
+  ,accumulated_total taler_amount NOT NULL
+  ,fee taler_amount NOT NULL
+  ,transferable taler_amount NOT NULL
+  ,fulfillment_state SMALLINT NOT NULL CHECK(fulfillment_state between 0 and 5)
   ,fulfillment_id BIGINT NULL REFERENCES policy_fulfillments (fulfillment_id) 
ON DELETE CASCADE
   );
 COMMENT ON TABLE policy_details
@@ -40,13 +36,13 @@ COMMENT ON COLUMN policy_details.policy_json
   IS 'JSON object with options set that the exchange needs to consider when 
executing a deposit. Supported details depend on the policy extensions 
supported by the exchange.';
 COMMENT ON COLUMN policy_details.deadline
   IS 'Deadline until the policy must be marked as fulfilled (maybe "forever")';
-COMMENT ON COLUMN policy_details.commitment_val
+COMMENT ON COLUMN policy_details.commitment
   IS 'The amount that this policy commits to.  Invariant: commitment >= fee';
-COMMENT ON COLUMN policy_details.accumulated_total_val
+COMMENT ON COLUMN policy_details.accumulated_total
   IS 'The sum of all contributions of all deposit that reference this policy.  
Invariant: The fulfilment_state must be Insufficient as long as 
accumulated_total < commitment';
-COMMENT ON COLUMN policy_details.fee_val
+COMMENT ON COLUMN policy_details.fee
   IS 'The fee for this policy, due when the policy is fulfilled or timed out';
-COMMENT ON COLUMN policy_details.transferable_val
+COMMENT ON COLUMN policy_details.transferable
   IS 'The amount that on fulfillment or timeout will be transferred to the 
payto-URI''s of the corresponding deposit''s.  The policy fees must have been 
already deducted from it.  Invariant: fee+transferable <= accumulated_total.  
The remaining amount (accumulated_total - fee - transferable) can be refreshed 
by the owner of the coins when the state is Timeout or Success.';
 COMMENT ON COLUMN policy_details.fulfillment_state
   IS 'State of the fulfillment:
diff --git a/src/exchangedb/0002-profit_drains.sql 
b/src/exchangedb/0002-profit_drains.sql
index 4aba9b46..e4a9bcb1 100644
--- a/src/exchangedb/0002-profit_drains.sql
+++ b/src/exchangedb/0002-profit_drains.sql
@@ -20,8 +20,7 @@ CREATE TABLE profit_drains
   ,account_section VARCHAR NOT NULL
   ,payto_uri VARCHAR NOT NULL
   ,trigger_date INT8 NOT NULL
-  ,amount_val INT8 NOT NULL
-  ,amount_frac INT4 NOT NULL
+  ,amount taler_amount NOT NULL
   ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
   ,executed BOOLEAN NOT NULL DEFAULT FALSE
   );
@@ -35,7 +34,7 @@ COMMENT ON COLUMN profit_drains.payto_uri
   IS 'specifies the account to be credited';
 COMMENT ON COLUMN profit_drains.trigger_date
   IS 'set by taler-exchange-offline at the time of making the signature; not 
necessarily the exact date of execution of the wire transfer, just for 
orientation';
-COMMENT ON COLUMN profit_drains.amount_val
+COMMENT ON COLUMN profit_drains.amount
   IS 'amount to be transferred';
 COMMENT ON COLUMN profit_drains.master_sig
   IS 'EdDSA signature of type TALER_SIGNATURE_MASTER_DRAIN_PROFIT';
diff --git a/src/exchangedb/0002-purse_deposits.sql 
b/src/exchangedb/0002-purse_deposits.sql
index 9452f434..17de48ee 100644
--- a/src/exchangedb/0002-purse_deposits.sql
+++ b/src/exchangedb/0002-purse_deposits.sql
@@ -29,8 +29,7 @@ BEGIN
       ',partner_serial_id INT8'
       ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
       ',coin_pub BYTEA NOT NULL'
-      ',amount_with_fee_val INT8 NOT NULL'
-      ',amount_with_fee_frac INT4 NOT NULL'
+      ',amount_with_fee taler_amount NOT NULL'
       ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
       ',PRIMARY KEY (purse_pub,coin_pub)'
     ') %s ;'
@@ -63,7 +62,7 @@ BEGIN
   );
   PERFORM comment_partitioned_column(
      'Total amount being deposited'
-    ,'amount_with_fee_val'
+    ,'amount_with_fee'
     ,table_name
     ,partition_suffix
   );
diff --git a/src/exchangedb/0002-purse_requests.sql 
b/src/exchangedb/0002-purse_requests.sql
index 5038c241..1d47c28f 100644
--- a/src/exchangedb/0002-purse_requests.sql
+++ b/src/exchangedb/0002-purse_requests.sql
@@ -34,12 +34,9 @@ BEGIN
       ',age_limit INT4 NOT NULL'
       ',flags INT4 NOT NULL'
       ',in_reserve_quota BOOLEAN NOT NULL DEFAULT(FALSE)'
-      ',amount_with_fee_val INT8 NOT NULL'
-      ',amount_with_fee_frac INT4 NOT NULL'
-      ',purse_fee_val INT8 NOT NULL'
-      ',purse_fee_frac INT4 NOT NULL'
-      ',balance_val INT8 NOT NULL DEFAULT (0)'
-      ',balance_frac INT4 NOT NULL DEFAULT (0)'
+      ',amount_with_fee taler_amount NOT NULL'
+      ',purse_fee taler_amount NOT NULL'
+      ',balance taler_amount NOT NULL DEFAULT (0,0)'
       ',purse_sig BYTEA NOT NULL CHECK(LENGTH(purse_sig)=64)'
       ',PRIMARY KEY (purse_pub)'
     ') %s ;'
@@ -90,19 +87,19 @@ BEGIN
   );
   PERFORM comment_partitioned_column(
      'Total amount expected to be in the purse'
-    ,'amount_with_fee_val'
+    ,'amount_with_fee'
     ,table_name
     ,partition_suffix
   );
   PERFORM comment_partitioned_column(
      'Purse fee the client agreed to pay from the reserve (accepted by the 
exchange at the time the purse was created). Zero if in_reserve_quota is TRUE.'
-    ,'purse_fee_val'
+    ,'purse_fee'
     ,table_name
     ,partition_suffix
   );
   PERFORM comment_partitioned_column(
     'Total amount actually in the purse (updated)'
-    ,'balance_val'
+    ,'balance'
     ,table_name
     ,partition_suffix
   );
diff --git a/src/exchangedb/0002-recoup.sql b/src/exchangedb/0002-recoup.sql
index 36e36d9d..7e7be78d 100644
--- a/src/exchangedb/0002-recoup.sql
+++ b/src/exchangedb/0002-recoup.sql
@@ -29,8 +29,7 @@ BEGIN
       ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
       ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
       ',coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)'
-      ',amount_val INT8 NOT NULL'
-      ',amount_frac INT4 NOT NULL'
+      ',amount taler_amount NOT NULL'
       ',recoup_timestamp INT8 NOT NULL'
       ',reserve_out_serial_id INT8 NOT NULL'
     ') %s ;'
diff --git a/src/exchangedb/0002-recoup_refresh.sql 
b/src/exchangedb/0002-recoup_refresh.sql
index bfcfb3d8..fde8e00e 100644
--- a/src/exchangedb/0002-recoup_refresh.sql
+++ b/src/exchangedb/0002-recoup_refresh.sql
@@ -31,8 +31,7 @@ BEGIN
     ',known_coin_id BIGINT NOT NULL'
     ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
     ',coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)'
-    ',amount_val INT8 NOT NULL'
-    ',amount_frac INT4 NOT NULL'
+    ',amount taler_amount NOT NULL'
     ',recoup_timestamp INT8 NOT NULL'
     ',rrc_serial INT8 NOT NULL'
     ') %s ;'
diff --git a/src/exchangedb/0002-refresh_commitments.sql 
b/src/exchangedb/0002-refresh_commitments.sql
index 328dad5c..21ab073c 100644
--- a/src/exchangedb/0002-refresh_commitments.sql
+++ b/src/exchangedb/0002-refresh_commitments.sql
@@ -29,8 +29,7 @@ BEGIN
       ',rc BYTEA PRIMARY KEY CHECK (LENGTH(rc)=64)'
       ',old_coin_pub BYTEA NOT NULL'
       ',old_coin_sig BYTEA NOT NULL CHECK(LENGTH(old_coin_sig)=64)'
-      ',amount_with_fee_val INT8 NOT NULL'
-      ',amount_with_fee_frac INT4 NOT NULL'
+      ',amount_with_fee taler_amount NOT NULL'
       ',noreveal_index INT4 NOT NULL'
     ') %s ;'
     ,table_name
diff --git a/src/exchangedb/0002-refunds.sql b/src/exchangedb/0002-refunds.sql
index 88af42db..caf69506 100644
--- a/src/exchangedb/0002-refunds.sql
+++ b/src/exchangedb/0002-refunds.sql
@@ -30,8 +30,7 @@ BEGIN
       ',deposit_serial_id INT8 NOT NULL'
       ',merchant_sig BYTEA NOT NULL CHECK(LENGTH(merchant_sig)=64)'
       ',rtransaction_id INT8 NOT NULL'
-      ',amount_with_fee_val INT8 NOT NULL'
-      ',amount_with_fee_frac INT4 NOT NULL'
+      ',amount_with_fee taler_amount NOT NULL'
     ') %s ;'
     ,table_name
     ,'PARTITION BY HASH (coin_pub)'
diff --git a/src/exchangedb/0002-reserves_close.sql 
b/src/exchangedb/0002-reserves_close.sql
index 52931b87..52a8d0a5 100644
--- a/src/exchangedb/0002-reserves_close.sql
+++ b/src/exchangedb/0002-reserves_close.sql
@@ -30,10 +30,8 @@ BEGIN
       ',execution_date INT8 NOT NULL'
       ',wtid BYTEA NOT NULL CHECK (LENGTH(wtid)=32)'
       ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
-      ',amount_val INT8 NOT NULL'
-      ',amount_frac INT4 NOT NULL'
-      ',closing_fee_val INT8 NOT NULL'
-      ',closing_fee_frac INT4 NOT NULL'
+      ',amount taler_amount NOT NULL'
+      ',closing_fee taler_amount NOT NULL'
       ',close_request_row INT8 NOT NULL DEFAULT(0)'
     ') %s ;'
     ,table_name
diff --git a/src/exchangedb/0002-reserves_in.sql 
b/src/exchangedb/0002-reserves_in.sql
index 410eca7c..c9c76f28 100644
--- a/src/exchangedb/0002-reserves_in.sql
+++ b/src/exchangedb/0002-reserves_in.sql
@@ -28,8 +28,7 @@ BEGIN
       '(reserve_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
       ',reserve_pub BYTEA PRIMARY KEY'
       ',wire_reference INT8 NOT NULL'
-      ',credit_val INT8 NOT NULL'
-      ',credit_frac INT4 NOT NULL'
+      ',credit taler_amount NOT NULL'
       ',wire_source_h_payto BYTEA CHECK (LENGTH(wire_source_h_payto)=32)'
       ',exchange_account_section TEXT NOT NULL'
       ',execution_date INT8 NOT NULL'
@@ -57,7 +56,7 @@ BEGIN
   );
   PERFORM comment_partitioned_column(
      'Amount that was transferred into the reserve'
-    ,'credit_val'
+    ,'credit'
     ,table_name
     ,partition_suffix
   );
diff --git a/src/exchangedb/0002-reserves_open_deposits.sql 
b/src/exchangedb/0002-reserves_open_deposits.sql
index 35605d36..c4cb4c30 100644
--- a/src/exchangedb/0002-reserves_open_deposits.sql
+++ b/src/exchangedb/0002-reserves_open_deposits.sql
@@ -30,8 +30,7 @@ BEGIN
       ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)'
       ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
       ',coin_sig BYTEA NOT NULL CHECK (LENGTH(coin_sig)=64)'
-      ',contribution_val INT8 NOT NULL'
-      ',contribution_frac INT4 NOT NULL'
+      ',contribution taler_amount NOT NULL'
     ') %s ;'
     ,table_name
     ,'PARTITION BY HASH (coin_pub)'
diff --git a/src/exchangedb/0002-reserves_open_requests.sql 
b/src/exchangedb/0002-reserves_open_requests.sql
index bbd5ec90..d913461c 100644
--- a/src/exchangedb/0002-reserves_open_requests.sql
+++ b/src/exchangedb/0002-reserves_open_requests.sql
@@ -30,8 +30,7 @@ BEGIN
       ',request_timestamp INT8 NOT NULL'
       ',expiration_date INT8 NOT NULL'
       ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
-      ',reserve_payment_val INT8 NOT NULL'
-      ',reserve_payment_frac INT4 NOT NULL'
+      ',reserve_payment taler_amount NOT NULL'
       ',requested_purse_limit INT4 NOT NULL'
     ') %s ;'
     ,table_name
@@ -45,7 +44,7 @@ BEGIN
   );
   PERFORM comment_partitioned_column (
      'Fee to pay for the request from the reserve balance itself.'
-    ,'reserve_payment_val'
+    ,'reserve_payment'
     ,table_name
     ,partition_suffix
   );
diff --git a/src/exchangedb/0002-reserves_out.sql 
b/src/exchangedb/0002-reserves_out.sql
index 25d717a5..3b28c22b 100644
--- a/src/exchangedb/0002-reserves_out.sql
+++ b/src/exchangedb/0002-reserves_out.sql
@@ -32,8 +32,7 @@ BEGIN
       ',reserve_uuid INT8 NOT NULL'
       ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
       ',execution_date INT8 NOT NULL'
-      ',amount_with_fee_val INT8 NOT NULL'
-      ',amount_with_fee_frac INT4 NOT NULL'
+      ',amount_with_fee taler_amount NOT NULL'
     ') %s ;'
     ,'reserves_out'
     ,'PARTITION BY HASH (h_blind_ev)'
diff --git a/src/exchangedb/0002-wad_in_entries.sql 
b/src/exchangedb/0002-wad_in_entries.sql
index 63c8bca2..99e07be2 100644
--- a/src/exchangedb/0002-wad_in_entries.sql
+++ b/src/exchangedb/0002-wad_in_entries.sql
@@ -32,12 +32,9 @@ BEGIN
       ',h_contract BYTEA NOT NULL CHECK(LENGTH(h_contract)=64)'
       ',purse_expiration INT8 NOT NULL'
       ',merge_timestamp INT8 NOT NULL'
-      ',amount_with_fee_val INT8 NOT NULL'
-      ',amount_with_fee_frac INT4 NOT NULL'
-      ',wad_fee_val INT8 NOT NULL'
-      ',wad_fee_frac INT4 NOT NULL'
-      ',deposit_fees_val INT8 NOT NULL'
-      ',deposit_fees_frac INT4 NOT NULL'
+      ',amount_with_fee taler_amount NOT NULL'
+      ',wad_fee taler_amount NOT NULL'
+      ',deposit_fees taler_amount NOT NULL'
       ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
       ',purse_sig BYTEA NOT NULL CHECK (LENGTH(purse_sig)=64)'
     ') %s ;'
@@ -88,19 +85,19 @@ BEGIN
   );
   PERFORM comment_partitioned_column(
      'Total amount in the purse'
-    ,'amount_with_fee_val'
+    ,'amount_with_fee'
     ,table_name
     ,partition_suffix
   );
   PERFORM comment_partitioned_column(
      'Total wad fees paid by the purse'
-    ,'wad_fee_val'
+    ,'wad_fee'
     ,table_name
     ,partition_suffix
   );
   PERFORM comment_partitioned_column(
      'Total deposit fees paid when depositing coins into the purse'
-    ,'deposit_fees_val'
+    ,'deposit_fees'
     ,table_name
     ,partition_suffix
   );
diff --git a/src/exchangedb/0002-wad_out_entries.sql 
b/src/exchangedb/0002-wad_out_entries.sql
index 45a4813c..80c0f9c7 100644
--- a/src/exchangedb/0002-wad_out_entries.sql
+++ b/src/exchangedb/0002-wad_out_entries.sql
@@ -33,12 +33,9 @@ BEGIN
      ',h_contract BYTEA NOT NULL CHECK(LENGTH(h_contract)=64)'
      ',purse_expiration INT8 NOT NULL'
      ',merge_timestamp INT8 NOT NULL'
-     ',amount_with_fee_val INT8 NOT NULL'
-     ',amount_with_fee_frac INT4 NOT NULL'
-     ',wad_fee_val INT8 NOT NULL'
-     ',wad_fee_frac INT4 NOT NULL'
-     ',deposit_fees_val INT8 NOT NULL'
-     ',deposit_fees_frac INT4 NOT NULL'
+     ',amount_with_fee taler_amount NOT NULL'
+     ',wad_fee taler_amount NOT NULL'
+     ',deposit_fees taler_amount NOT NULL'
      ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
      ',purse_sig BYTEA NOT NULL CHECK (LENGTH(purse_sig)=64)'
      ') %s ;'
@@ -89,19 +86,19 @@ BEGIN
   );
   PERFORM comment_partitioned_column(
      'Total amount in the purse'
-    ,'amount_with_fee_val'
+    ,'amount_with_fee'
     ,table_name
     ,partition_suffix
   );
   PERFORM comment_partitioned_column(
     'Wad fee charged to the purse'
-    ,'wad_fee_val'
+    ,'wad_fee'
     ,table_name
     ,partition_suffix
   );
   PERFORM comment_partitioned_column(
      'Total deposit fees charged to the purse'
-    ,'deposit_fees_val'
+    ,'deposit_fees'
     ,table_name
     ,partition_suffix
   );
diff --git a/src/exchangedb/0002-wads_in.sql b/src/exchangedb/0002-wads_in.sql
index 013b1635..e45f3da2 100644
--- a/src/exchangedb/0002-wads_in.sql
+++ b/src/exchangedb/0002-wads_in.sql
@@ -28,8 +28,7 @@ BEGIN
      '(wad_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
      ',wad_id BYTEA PRIMARY KEY CHECK (LENGTH(wad_id)=24)'
      ',origin_exchange_url TEXT NOT NULL'
-     ',amount_val INT8 NOT NULL'
-     ',amount_frac INT4 NOT NULL'
+     ',amount taler_amount NOT NULL'
      ',arrival_time INT8 NOT NULL'
      ',UNIQUE (wad_id, origin_exchange_url)'
      ') %s ;'
@@ -56,7 +55,7 @@ BEGIN
   );
   PERFORM comment_partitioned_column(
      'Actual amount that was received by our exchange'
-    ,'amount_val'
+    ,'amount'
     ,table_name
     ,partition_suffix
   );
diff --git a/src/exchangedb/0002-wads_out.sql b/src/exchangedb/0002-wads_out.sql
index edad4a68..a419bc86 100644
--- a/src/exchangedb/0002-wads_out.sql
+++ b/src/exchangedb/0002-wads_out.sql
@@ -28,8 +28,7 @@ BEGIN
       '(wad_out_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
       ',wad_id BYTEA PRIMARY KEY CHECK (LENGTH(wad_id)=24)'
       ',partner_serial_id INT8 NOT NULL'
-      ',amount_val INT8 NOT NULL'
-      ',amount_frac INT4 NOT NULL'
+      ',amount taler_amount NOT NULL'
       ',execution_time INT8 NOT NULL'
     ') %s ;'
     ,table_name
@@ -55,7 +54,7 @@ BEGIN
   );
   PERFORM comment_partitioned_column(
      'Amount that was wired'
-    ,'amount_val'
+    ,'amount'
     ,table_name
     ,shard_suffix
   );
diff --git a/src/exchangedb/0002-wire_fee.sql b/src/exchangedb/0002-wire_fee.sql
index deb26cef..4909992a 100644
--- a/src/exchangedb/0002-wire_fee.sql
+++ b/src/exchangedb/0002-wire_fee.sql
@@ -19,10 +19,8 @@ CREATE TABLE wire_fee
   ,wire_method VARCHAR NOT NULL
   ,start_date INT8 NOT NULL
   ,end_date INT8 NOT NULL
-  ,wire_fee_val INT8 NOT NULL
-  ,wire_fee_frac INT4 NOT NULL
-  ,closing_fee_val INT8 NOT NULL
-  ,closing_fee_frac INT4 NOT NULL
+  ,wire_fee taler_amount NOT NULL
+  ,closing_fee taler_amount NOT NULL
   ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
   ,PRIMARY KEY (wire_method, start_date)
   );
diff --git a/src/exchangedb/0002-wire_out.sql b/src/exchangedb/0002-wire_out.sql
index 9c459fe9..2d7e9595 100644
--- a/src/exchangedb/0002-wire_out.sql
+++ b/src/exchangedb/0002-wire_out.sql
@@ -30,9 +30,8 @@ BEGIN
       ',wtid_raw BYTEA UNIQUE NOT NULL CHECK (LENGTH(wtid_raw)=32)'
       ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
       ',exchange_account_section TEXT NOT NULL'
-      ',amount_val INT8 NOT NULL'
-      ',amount_frac INT4 NOT NULL'
-    ') %s ;'
+      ',amount taler_amount NOT NULL'
+      ') %s ;'
     ,table_name
     ,'PARTITION BY HASH (wtid_raw)'
     ,partition_suffix
diff --git a/src/exchangedb/exchange_do_batch_coin_known.sql 
b/src/exchangedb/exchange_do_batch_coin_known.sql
index f6a14cfa..db96cb08 100644
--- a/src/exchangedb/exchange_do_batch_coin_known.sql
+++ b/src/exchangedb/exchange_do_batch_coin_known.sql
@@ -53,7 +53,7 @@ BEGIN
 WITH dd AS (
 SELECT
   denominations_serial,
-  coin_val, coin_frac
+  coin
   FROM denominations
     WHERE denom_pub_hash
     IN
@@ -87,16 +87,14 @@ SELECT
       denominations_serial,
       age_commitment_hash,
       denom_sig,
-      remaining_val,
-      remaining_frac
+      remaining
       )
       SELECT
         ir.coin_pub,
         dd.denominations_serial,
         ir.age_commitment_hash,
         ir.denom_sig,
-        dd.coin_val,
-        dd.coin_frac
+        dd.coin
         FROM input_rows ir
         JOIN dd
           ON dd.denom_pub_hash = ir.denom_pub_hash
@@ -218,7 +216,7 @@ BEGIN
 WITH dd AS (
 SELECT
   denominations_serial,
-  coin_val, coin_frac
+  coin
   FROM denominations
     WHERE denom_pub_hash
     IN
@@ -242,16 +240,14 @@ SELECT
       denominations_serial,
       age_commitment_hash,
       denom_sig,
-      remaining_val,
-      remaining_frac
+      remaining
       )
       SELECT
         ir.coin_pub,
         dd.denominations_serial,
         ir.age_commitment_hash,
         ir.denom_sig,
-        dd.coin_val,
-        dd.coin_frac
+        dd.coin
         FROM input_rows ir
         JOIN dd
           ON dd.denom_pub_hash = ir.denom_pub_hash
@@ -324,7 +320,7 @@ BEGIN
 WITH dd AS (
 SELECT
   denominations_serial,
-  coin_val, coin_frac
+  coin
   FROM denominations
     WHERE denom_pub_hash
     IN
@@ -344,16 +340,14 @@ SELECT
       denominations_serial,
       age_commitment_hash,
       denom_sig,
-      remaining_val,
-      remaining_frac
+      remaining
       )
       SELECT
         ir.coin_pub,
         dd.denominations_serial,
         ir.age_commitment_hash,
         ir.denom_sig,
-        dd.coin_val,
-        dd.coin_frac
+        dd.coin
         FROM input_rows ir
         JOIN dd
           ON dd.denom_pub_hash = ir.denom_pub_hash
@@ -430,8 +424,8 @@ BEGIN
         in_denom_sig2 AS denom_sig
       WHERE i = 2
     );
-    WITH dd (denominations_serial, coin_val, coin_frac) AS (
-      SELECT denominations_serial, coin_val, coin_frac
+    WITH dd (denominations_serial, coin) AS (
+      SELECT denominations_serial, coin
       FROM denominations
       WHERE denom_pub_hash = ins_values.denom_pub_hash
     ),
@@ -444,15 +438,13 @@ BEGIN
         denominations_serial,
         age_commitment_hash,
         denom_sig,
-        remaining_val,
-        remaining_frac
+        remaining
       ) SELECT
         input_rows.coin_pub,
         dd.denominations_serial,
         ins_values.age_commitment_hash,
         ins_values.denom_sig,
-        coin_val,
-        coin_frac
+        coin
       FROM dd
       CROSS JOIN input_rows
       ON CONFLICT DO NOTHING
diff --git a/src/exchangedb/exchange_do_batch_reserves_update.sql 
b/src/exchangedb/exchange_do_batch_reserves_update.sql
index da7f4508..8dda84af 100644
--- a/src/exchangedb/exchange_do_batch_reserves_update.sql
+++ b/src/exchangedb/exchange_do_batch_reserves_update.sql
@@ -29,16 +29,14 @@ BEGIN
   INSERT INTO reserves_in
     (reserve_pub
     ,wire_reference
-    ,credit_val
-    ,credit_frac
+    ,credit
     ,exchange_account_section
     ,wire_source_h_payto
     ,execution_date)
     VALUES
     (in_reserve_pub
     ,in_wire_ref
-    ,in_credit.val
-    ,in_credit.frac
+    ,in_credit
     ,in_exchange_account_name
     ,in_wire_source_h_payto
     ,in_expiration_date)
@@ -47,17 +45,17 @@ BEGIN
   THEN
     --IF THE INSERTION WAS A SUCCESS IT MEANS NO DUPLICATED TRANSACTION
     out_duplicate = FALSE;
-    UPDATE reserves
+    UPDATE reserves rs
       SET
-         current_balance.frac = current_balance.frac+in_credit.frac
+         current_balance.frac = (rs.current_balance).frac+in_credit.frac
            - CASE
-             WHEN current_balance.frac + in_credit.frac >= 100000000
+             WHEN (rs.current_balance).frac + in_credit.frac >= 100000000
                THEN 100000000
              ELSE 1
              END
-            ,current_balance.val = current_balance.val+in_credit.val
+        ,current_balance.val = (rs.current_balance).val+in_credit.val
            + CASE
-             WHEN current_balance.frac + in_credit.frac >= 100000000
+             WHEN (rs.current_balance).frac + in_credit.frac >= 100000000
                THEN 1
              ELSE 0
              END
diff --git a/src/exchangedb/exchange_do_batch_withdraw_insert.sql 
b/src/exchangedb/exchange_do_batch_withdraw_insert.sql
index fd00754a..d36181a6 100644
--- a/src/exchangedb/exchange_do_batch_withdraw_insert.sql
+++ b/src/exchangedb/exchange_do_batch_withdraw_insert.sql
@@ -64,8 +64,7 @@ INSERT INTO exchange.reserves_out
   ,reserve_uuid
   ,reserve_sig
   ,execution_date
-  ,amount_with_fee_val
-  ,amount_with_fee_frac)
+  ,amount_with_fee)
 VALUES
   (h_coin_envelope
   ,denom_serial
@@ -73,8 +72,7 @@ VALUES
   ,ruuid
   ,reserve_sig
   ,now
-  ,amount.val
-  ,amount.frac)
+  ,amount)
 ON CONFLICT DO NOTHING;
 
 IF NOT FOUND
@@ -120,4 +118,3 @@ END $$;
 
 COMMENT ON FUNCTION exchange_do_batch_withdraw_insert(BYTEA, taler_amount, 
BYTEA, INT8, BYTEA, BYTEA, BYTEA, INT8)
   IS 'Stores information about a planchet for a batch withdraw operation. 
Checks if the planchet already exists, and in that case indicates a conflict';
-
diff --git a/src/exchangedb/exchange_do_deposit.sql 
b/src/exchangedb/exchange_do_deposit.sql
index 6e522b35..4e8374b8 100644
--- a/src/exchangedb/exchange_do_deposit.sql
+++ b/src/exchangedb/exchange_do_deposit.sql
@@ -14,8 +14,7 @@
 -- TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 --
 CREATE OR REPLACE FUNCTION exchange_do_deposit(
-  IN in_amount_with_fee_val INT8,
-  IN in_amount_with_fee_frac INT4,
+  IN in_amount_with_fee taler_amount,
   IN in_h_contract_terms BYTEA,
   IN in_wire_salt BYTEA,
   IN in_wallet_timestamp INT8,
@@ -66,8 +65,7 @@ INSERT INTO exchange.deposits
   (shard
   ,coin_pub
   ,known_coin_id
-  ,amount_with_fee_val
-  ,amount_with_fee_frac
+  ,amount_with_fee
   ,wallet_timestamp
   ,exchange_timestamp
   ,refund_deadline
@@ -84,8 +82,7 @@ INSERT INTO exchange.deposits
   (in_shard
   ,in_coin_pub
   ,in_known_coin_id
-  ,in_amount_with_fee_val
-  ,in_amount_with_fee_frac
+  ,in_amount_with_fee
   ,in_wallet_timestamp
   ,in_exchange_timestamp
   ,in_refund_deadline
@@ -138,24 +135,24 @@ END IF;
 out_exchange_timestamp=in_exchange_timestamp;
 
 -- Check and update balance of the coin.
-UPDATE known_coins
+UPDATE known_coins kc
   SET
-    remaining_frac=remaining_frac-in_amount_with_fee_frac
+    remaining.frac=(kc.remaining).frac-in_amount_with_fee.frac
        + CASE
-         WHEN remaining_frac < in_amount_with_fee_frac
+         WHEN (kc.remaining).frac < in_amount_with_fee.frac
          THEN 100000000
          ELSE 0
          END,
-    remaining_val=remaining_val-in_amount_with_fee_val
+    remaining.val=(kc.remaining).val-in_amount_with_fee.val
        - CASE
-         WHEN remaining_frac < in_amount_with_fee_frac
+         WHEN (kc.remaining).frac < in_amount_with_fee.frac
          THEN 1
          ELSE 0
          END
   WHERE coin_pub=in_coin_pub
-    AND ( (remaining_val > in_amount_with_fee_val) OR
-          ( (remaining_frac >= in_amount_with_fee_frac) AND
-            (remaining_val >= in_amount_with_fee_val) ) );
+    AND ( ((kc.remaining).val > in_amount_with_fee.val) OR
+          ( ((kc.remaining).frac >= in_amount_with_fee.frac) AND
+            ((kc.remaining).val >= in_amount_with_fee.val) ) );
 
 IF NOT FOUND
 THEN
diff --git a/src/exchangedb/exchange_do_expire_purse.sql 
b/src/exchangedb/exchange_do_expire_purse.sql
index 82756abc..2d9f7e09 100644
--- a/src/exchangedb/exchange_do_expire_purse.sql
+++ b/src/exchangedb/exchange_do_expire_purse.sql
@@ -71,21 +71,20 @@ END IF;
 -- restore balance to each coin deposited into the purse
 FOR my_deposit IN
   SELECT coin_pub
-        ,amount_with_fee_val
-        ,amount_with_fee_frac
-    FROM exchange.purse_deposits
+        ,amount_with_fee
+    FROM purse_deposits
   WHERE purse_pub = my_purse_pub
 LOOP
-  UPDATE exchange.known_coins SET
-    remaining_frac=remaining_frac+my_deposit.amount_with_fee_frac
+  UPDATE known_coins kc SET
+    remaining.frac=(kc.remaining).frac+(my_deposit.amount_with_fee).frac
      - CASE
-       WHEN remaining_frac+my_deposit.amount_with_fee_frac >= 100000000
+       WHEN (kc.remaining).frac+(my_deposit.amount_with_fee).frac >= 100000000
        THEN 100000000
        ELSE 0
        END,
-    remaining_val=remaining_val+my_deposit.amount_with_fee_val
+    remaining.val=(kc.remaining).val+(my_deposit.amount_with_fee).val
      + CASE
-       WHEN remaining_frac+my_deposit.amount_with_fee_frac >= 100000000
+       WHEN (kc.remaining).frac+(my_deposit.amount_with_fee).frac >= 100000000
        THEN 1
        ELSE 0
        END
@@ -95,5 +94,3 @@ END $$;
 
 COMMENT ON FUNCTION exchange_do_expire_purse(INT8,INT8,INT8)
   IS 'Finds an expired purse in the given time range and refunds the coins (if 
any).';
-
-
diff --git a/src/exchangedb/exchange_do_history_request.sql 
b/src/exchangedb/exchange_do_history_request.sql
index 5cd15bc6..726c853f 100644
--- a/src/exchangedb/exchange_do_history_request.sql
+++ b/src/exchangedb/exchange_do_history_request.sql
@@ -35,14 +35,12 @@ BEGIN
   (reserve_pub
   ,request_timestamp
   ,reserve_sig
-  ,history_fee_val
-  ,history_fee_frac)
+  ,history_fee)
   VALUES
   (in_reserve_pub
   ,in_request_timestamp
   ,in_reserve_sig
-  ,in_history_fee.val
-  ,in_history_fee.frac)
+  ,in_history_fee)
   ON CONFLICT DO NOTHING;
 
   IF NOT FOUND
@@ -101,4 +99,3 @@ BEGIN
   out_balance_ok=TRUE;
 
 END $$;
-
diff --git a/src/exchangedb/exchange_do_insert_aml_decision.sql 
b/src/exchangedb/exchange_do_insert_aml_decision.sql
index f257675a..d4f752d1 100644
--- a/src/exchangedb/exchange_do_insert_aml_decision.sql
+++ b/src/exchangedb/exchange_do_insert_aml_decision.sql
@@ -16,8 +16,7 @@
 
 CREATE OR REPLACE FUNCTION exchange_do_insert_aml_decision(
   IN in_h_payto BYTEA,
-  IN in_new_threshold_val INT8,
-  IN in_new_threshold_frac INT4,
+  IN in_new_threshold taler_amount,
   IN in_new_status INT4,
   IN in_decision_time INT8,
   IN in_justification VARCHAR,
@@ -59,8 +58,7 @@ THEN
     RETURN;
   END IF;
   UPDATE exchange.aml_status
-    SET threshold_val=in_new_threshold_val
-       ,threshold_frac=in_new_threshold_frac
+    SET threshold=in_new_threshold
        ,status=in_new_status
        ,kyc_requirement=in_requirement_row
    WHERE h_payto=in_h_payto;
@@ -69,14 +67,12 @@ ELSE
   out_last_date = 0;
   INSERT INTO exchange.aml_status
     (h_payto
-    ,threshold_val
-    ,threshold_frac
+    ,threshold
     ,status
     ,kyc_requirement)
     VALUES
     (in_h_payto
-    ,in_new_threshold_val
-    ,in_new_threshold_frac
+    ,in_new_threshold
     ,in_new_status
     ,in_requirement_row);
 END IF;
@@ -84,8 +80,7 @@ END IF;
 
 INSERT INTO exchange.aml_history
   (h_payto
-  ,new_threshold_val
-  ,new_threshold_frac
+  ,new_threshold
   ,new_status
   ,decision_time
   ,justification
@@ -95,8 +90,7 @@ INSERT INTO exchange.aml_history
   ,decider_sig
   ) VALUES
   (in_h_payto
-  ,in_new_threshold_val
-  ,in_new_threshold_frac
+  ,in_new_threshold
   ,in_new_status
   ,in_decision_time
   ,in_justification
@@ -125,5 +119,5 @@ END IF;
 END $$;
 
 
-COMMENT ON FUNCTION exchange_do_insert_aml_decision(BYTEA, INT8, INT4, INT4, 
INT8, VARCHAR, BYTEA, BYTEA, VARCHAR, VARCHAR, INT8)
+COMMENT ON FUNCTION exchange_do_insert_aml_decision(BYTEA, taler_amount, INT4, 
INT8, VARCHAR, BYTEA, BYTEA, VARCHAR, VARCHAR, INT8)
   IS 'Checks whether the AML officer is eligible to make AML decisions and if 
so inserts the decision into the table';
diff --git a/src/exchangedb/exchange_do_insert_or_update_policy_details.sql 
b/src/exchangedb/exchange_do_insert_or_update_policy_details.sql
index c7fe64d1..1075195a 100644
--- a/src/exchangedb/exchange_do_insert_or_update_policy_details.sql
+++ b/src/exchangedb/exchange_do_insert_or_update_policy_details.sql
@@ -18,52 +18,40 @@ CREATE OR REPLACE FUNCTION 
exchange_do_insert_or_update_policy_details(
   IN in_policy_hash_code BYTEA,
   IN in_policy_json VARCHAR,
   IN in_deadline INT8,
-  IN in_commitment_val INT8,
-  IN in_commitment_frac INT4,
-  IN in_accumulated_total_val INT8,
-  IN in_accumulated_total_frac INT4,
-  IN in_fee_val INT8,
-  IN in_fee_frac INT4,
-  IN in_transferable_val INT8,
-  IN in_transferable_frac INT4,
+  IN in_commitment taler_amount,
+  IN in_accumulated_total taler_amount,
+  IN in_fee taler_amount,
+  IN in_transferable taler_amount,
   IN in_fulfillment_state SMALLINT,
   OUT out_policy_details_serial_id INT8,
-  OUT out_accumulated_total_val INT8,
-  OUT out_accumulated_total_frac INT4,
+  OUT out_accumulated_total taler_amount,
   OUT out_fulfillment_state SMALLINT)
 LANGUAGE plpgsql
 AS $$
 DECLARE
-       cur_commitment_val INT8;
-       cur_commitment_frac INT4;
-       cur_accumulated_total_val INT8;
-       cur_accumulated_total_frac INT4;
+    cur_commitment taler_amount;
+DECLARE
+    cur_accumulated_total taler_amount;
+DECLARE
+    rval RECORD;
 BEGIN
        -- First, try to create a new entry.
        INSERT INTO policy_details
                (policy_hash_code,
                 policy_json,
                 deadline,
-                commitment_val,
-                commitment_frac,
-                accumulated_total_val,
-                accumulated_total_frac,
-                fee_val,
-                fee_frac,
-                transferable_val,
-                transferable_frac,
+                commitment,
+                accumulated_total,
+                fee,
+                transferable,
                 fulfillment_state)
        VALUES (in_policy_hash_code,
                 in_policy_json,
                 in_deadline,
-                in_commitment_val,
-                in_commitment_frac,
-                in_accumulated_total_val,
-                in_accumulated_total_frac,
-                in_fee_val,
-                in_fee_frac,
-                in_transferable_val,
-                in_transferable_frac,
+                in_commitment,
+                in_accumulated_total,
+                in_fee,
+                in_transferable,
                 in_fulfillment_state)
        ON CONFLICT (policy_hash_code) DO NOTHING
        RETURNING policy_details_serial_id INTO out_policy_details_serial_id;
@@ -71,34 +59,33 @@ BEGIN
        -- If the insert was successful, return
        -- We assume that the fullfilment_state was correct in first place.
        IF FOUND THEN
-               out_accumulated_total_val  = in_accumulated_total_val;
-               out_accumulated_total_frac = in_accumulated_total_frac;
-               out_fulfillment_state      = in_fulfillment_state;
+               out_accumulated_total = in_accumulated_total;
+               out_fulfillment_state = in_fulfillment_state;
                RETURN;
        END IF;
 
        -- We had a conflict, grab the parts we need to update.
-       SELECT policy_details_serial_id,
-               commitment_val,
-               commitment_frac,
-               accumulated_total_val,
-               accumulated_total_frac
-       INTO out_policy_details_serial_id,
-               cur_commitment_val,
-               cur_commitment_frac,
-               cur_accumulated_total_val,
-               cur_accumulated_total_frac
+       SELECT policy_details_serial_id
+         ,commitment
+         ,accumulated_total
+       INTO rval
        FROM policy_details
        WHERE policy_hash_code = in_policy_hash_code;
 
+       -- We use rval as workaround as we cannot select
+       -- directly into the amount due to Postgres limitations.
+       out_policy_details_serial_id := rval.policy_details_serial_id;
+       cur_commitment := rval.commitment;
+       cur_accumulated_total := rval.accumulated_total;
+
        -- calculate the new values (overflows throws exception)
-       out_accumulated_total_val  = cur_accumulated_total_val  + 
in_accumulated_total_val;
-       out_accumulated_total_frac = cur_accumulated_total_frac + 
in_accumulated_total_frac;
+       out_accumulated_total.val  = cur_accumulated_total.val  + 
in_accumulated_total.val;
+       out_accumulated_total.frac = cur_accumulated_total.frac + 
in_accumulated_total.frac;
        -- normalize
-       out_accumulated_total_val = out_accumulated_total_val + 
out_accumulated_total_frac / 100000000;
-       out_accumulated_total_frac = out_accumulated_total_frac % 100000000;
+       out_accumulated_total.val = out_accumulated_total.val + 
out_accumulated_total.frac / 100000000;
+       out_accumulated_total.frac = out_accumulated_total.frac % 100000000;
 
-       IF (out_accumulated_total_val > (1 << 52))
+       IF (out_accumulated_total.val > (1 << 52))
        THEN
                RAISE EXCEPTION 'accumulation overflow';
        END IF;
@@ -109,9 +96,9 @@ BEGIN
        -- FIXME: What to do in case of Failure or other state?
        IF (out_fullfillment_state = 1) -- INSUFFICIENT
        THEN
-               IF (out_accumulated_total_val >= cur_commitment_val OR
-                       (out_accumulated_total_val = cur_commitment_val AND
-                               out_accumulated_total_frac >= 
cur_commitment_frac))
+               IF (out_accumulated_total.val >= cur_commitment.val OR
+                       (out_accumulated_total.val = cur_commitment.val AND
+                               out_accumulated_total.frac >= 
cur_commitment.frac))
                THEN
                        out_fulfillment_state = 2; -- READY
                END IF;
@@ -120,8 +107,7 @@ BEGIN
        -- Now, update the record
        UPDATE exchange.policy_details
        SET
-               accumulated_val  = out_accumulated_total_val,
-               accumulated_frac = out_accumulated_total_frac,
+               accumulated  = out_accumulated_total,
                fulfillment_state = out_fulfillment_state
        WHERE
                policy_details_serial_id = out_policy_details_serial_id;
diff --git a/src/exchangedb/exchange_do_melt.sql 
b/src/exchangedb/exchange_do_melt.sql
index c0290b56..7451577d 100644
--- a/src/exchangedb/exchange_do_melt.sql
+++ b/src/exchangedb/exchange_do_melt.sql
@@ -19,8 +19,7 @@
 
 CREATE OR REPLACE FUNCTION exchange_do_melt(
   IN in_cs_rms BYTEA,
-  IN in_amount_with_fee_val INT8,
-  IN in_amount_with_fee_frac INT4,
+  IN in_amount_with_fee taler_amount,
   IN in_rc BYTEA,
   IN in_old_coin_pub BYTEA,
   IN in_old_coin_sig BYTEA,
@@ -45,16 +44,14 @@ INSERT INTO exchange.refresh_commitments
   (rc
   ,old_coin_pub
   ,old_coin_sig
-  ,amount_with_fee_val
-  ,amount_with_fee_frac
+  ,amount_with_fee
   ,noreveal_index
   )
   VALUES
   (in_rc
   ,in_old_coin_pub
   ,in_old_coin_sig
-  ,in_amount_with_fee_val
-  ,in_amount_with_fee_frac
+  ,in_amount_with_fee
   ,in_noreveal_index)
   ON CONFLICT DO NOTHING;
 
@@ -104,24 +101,24 @@ out_zombie_bad=FALSE; -- zombie is OK
 
 
 -- Check and update balance of the coin.
-UPDATE known_coins
+UPDATE known_coins kc
   SET
-    remaining_frac=remaining_frac-in_amount_with_fee_frac
+    remaining.frac=(kc.remaining).frac-in_amount_with_fee.frac
        + CASE
-         WHEN remaining_frac < in_amount_with_fee_frac
+         WHEN (kc.remaining).frac < in_amount_with_fee.frac
          THEN 100000000
          ELSE 0
          END,
-    remaining_val=remaining_val-in_amount_with_fee_val
+    remaining.val=(kc.remaining).val-in_amount_with_fee.val
        - CASE
-         WHEN remaining_frac < in_amount_with_fee_frac
+         WHEN (kc.remaining).frac < in_amount_with_fee.frac
          THEN 1
          ELSE 0
          END
   WHERE coin_pub=in_old_coin_pub
-    AND ( (remaining_val > in_amount_with_fee_val) OR
-          ( (remaining_frac >= in_amount_with_fee_frac) AND
-            (remaining_val >= in_amount_with_fee_val) ) );
+    AND ( ((kc.remaining).val > in_amount_with_fee.val) OR
+          ( ((kc.remaining).frac >= in_amount_with_fee.frac) AND
+            ((kc.remaining).val >= in_amount_with_fee.val) ) );
 
 IF NOT FOUND
 THEN
@@ -183,4 +180,3 @@ out_balance_ok=TRUE;
 out_noreveal_index=in_noreveal_index;
 
 END $$;
-
diff --git a/src/exchangedb/exchange_do_purse_delete.sql 
b/src/exchangedb/exchange_do_purse_delete.sql
index 096475b4..5668f7be 100644
--- a/src/exchangedb/exchange_do_purse_delete.sql
+++ b/src/exchangedb/exchange_do_purse_delete.sql
@@ -91,21 +91,20 @@ END IF;
 -- restore balance to each coin deposited into the purse
 FOR my_deposit IN
   SELECT coin_pub
-        ,amount_with_fee_val
-        ,amount_with_fee_frac
+        ,amount_with_fee
     FROM exchange.purse_deposits
   WHERE purse_pub = in_purse_pub
 LOOP
-  UPDATE exchange.known_coins SET
-    remaining_frac=remaining_frac+my_deposit.amount_with_fee_frac
+  UPDATE known_coins kc SET
+    remaining.frac=(kc.remaining).frac+(my_deposit.amount_with_fee).frac
      - CASE
-       WHEN remaining_frac+my_deposit.amount_with_fee_frac >= 100000000
+       WHEN (kc.remaining).frac+(my_deposit.amount_with_fee).frac >= 100000000
        THEN 100000000
        ELSE 0
        END,
-    remaining_val=remaining_val+my_deposit.amount_with_fee_val
+    remaining.val=(kc.remaining).val+(my_deposit.amount_with_fee).val
      + CASE
-       WHEN remaining_frac+my_deposit.amount_with_fee_frac >= 100000000
+       WHEN (kc.remaining).frac+(my_deposit.amount_with_fee).frac >= 100000000
        THEN 1
        ELSE 0
        END
diff --git a/src/exchangedb/exchange_do_purse_deposit.sql 
b/src/exchangedb/exchange_do_purse_deposit.sql
index 45bdcdf6..0127ad23 100644
--- a/src/exchangedb/exchange_do_purse_deposit.sql
+++ b/src/exchangedb/exchange_do_purse_deposit.sql
@@ -30,11 +30,18 @@ LANGUAGE plpgsql
 AS $$
 DECLARE
   was_merged BOOLEAN;
+DECLARE
   psi INT8; -- partner's serial ID (set if merged)
+DECLARE
   my_amount taler_amount; -- total in purse
+DECLARE
   was_paid BOOLEAN;
+DECLARE
   my_in_reserve_quota BOOLEAN;
+DECLARE
   my_reserve_pub BYTEA;
+DECLARE
+  rval RECORD;
 BEGIN
 
 -- Store the deposit request.
@@ -42,15 +49,13 @@ INSERT INTO exchange.purse_deposits
   (partner_serial_id
   ,purse_pub
   ,coin_pub
-  ,amount_with_fee_val
-  ,amount_with_fee_frac
+  ,amount_with_fee
   ,coin_sig)
   VALUES
   (in_partner_id
   ,in_purse_pub
   ,in_coin_pub
-  ,in_amount_with_fee.val
-  ,in_amount_with_fee.frac
+  ,in_amount_with_fee
   ,in_coin_sig)
   ON CONFLICT DO NOTHING;
 
@@ -96,24 +101,24 @@ END IF;
 
 -- Debit the coin
 -- Check and update balance of the coin.
-UPDATE known_coins
+UPDATE known_coins kc
   SET
-    remaining_frac=remaining_frac-in_amount_with_fee.frac
+    remaining.frac=(kc.remaining).frac-in_amount_with_fee.frac
        + CASE
-         WHEN remaining_frac < in_amount_with_fee.frac
+         WHEN (kc.remaining).frac < in_amount_with_fee.frac
          THEN 100000000
          ELSE 0
          END,
-    remaining_val=remaining_val-in_amount_with_fee.val
+    remaining.val=(kc.remaining).val-in_amount_with_fee.val
        - CASE
-         WHEN remaining_frac < in_amount_with_fee.frac
+         WHEN (kc.remaining).frac < in_amount_with_fee.frac
          THEN 1
          ELSE 0
          END
   WHERE coin_pub=in_coin_pub
-    AND ( (remaining_val > in_amount_with_fee.val) OR
-          ( (remaining_frac >= in_amount_with_fee.frac) AND
-            (remaining_val >= in_amount_with_fee.val) ) );
+    AND ( ((kc.remaining).val > in_amount_with_fee.val) OR
+          ( ((kc.remaining).frac >= in_amount_with_fee.frac) AND
+            ((kc.remaining).val >= in_amount_with_fee.val) ) );
 
 IF NOT FOUND
 THEN
@@ -126,17 +131,17 @@ END IF;
 
 
 -- Credit the purse.
-UPDATE purse_requests
+UPDATE purse_requests pr
   SET
-    balance_frac=balance_frac+in_amount_without_fee.frac
+    balance.frac=(pr.balance).frac+in_amount_without_fee.frac
        - CASE
-         WHEN balance_frac+in_amount_without_fee.frac >= 100000000
+         WHEN (pr.balance).frac+in_amount_without_fee.frac >= 100000000
          THEN 100000000
          ELSE 0
          END,
-    balance_val=balance_val+in_amount_without_fee.val
+    balance.val=(pr.balance).val+in_amount_without_fee.val
        + CASE
-         WHEN balance_frac+in_amount_without_fee.frac >= 100000000
+         WHEN (pr.balance).frac+in_amount_without_fee.frac >= 100000000
          THEN 1
          ELSE 0
          END
@@ -161,24 +166,26 @@ THEN
 END IF;
 
 SELECT
-    amount_with_fee_val
-   ,amount_with_fee_frac
+    amount_with_fee
    ,in_reserve_quota
   INTO
-    my_amount.val
-   ,my_amount.frac
-   ,my_in_reserve_quota
-  FROM exchange.purse_requests
+    rval
+  FROM exchange.purse_requests preq
   WHERE (purse_pub=in_purse_pub)
-    AND ( ( ( (amount_with_fee_val <= balance_val)
-          AND (amount_with_fee_frac <= balance_frac) )
-         OR (amount_with_fee_val < balance_val) ) );
+    AND ( ( ( ((preq.amount_with_fee).val <= (preq.balance).val)
+          AND ((preq.amount_with_fee).frac <= (preq.balance).frac) )
+         OR ((preq.amount_with_fee).val < (preq.balance).val) ) );
 IF NOT FOUND
 THEN
   out_late=FALSE;
   RETURN;
 END IF;
 
+-- We use rval as workaround as we cannot select
+-- directly into the amount due to Postgres limitations.
+my_amount := rval.amount_with_fee;
+my_in_reserve_quota := rval.in_reserve_quota;
+
 -- Remember how this purse was finished.
 INSERT INTO purse_decision
   (purse_pub
diff --git a/src/exchangedb/exchange_do_purse_merge.sql 
b/src/exchangedb/exchange_do_purse_merge.sql
index 9780c016..b911a5a2 100644
--- a/src/exchangedb/exchange_do_purse_merge.sql
+++ b/src/exchangedb/exchange_do_purse_merge.sql
@@ -30,10 +30,17 @@ LANGUAGE plpgsql
 AS $$
 DECLARE
   my_amount taler_amount;
+DECLARE
   my_purse_fee taler_amount;
+DECLARE
   my_partner_serial_id INT8;
+DECLARE
   my_in_reserve_quota BOOLEAN;
+DECLARE
+  rval RECORD;
+DECLARE
   reserve RECORD;
+DECLARE
   balance taler_amount;
 BEGIN
 
@@ -60,29 +67,29 @@ END IF;
 
 out_no_partner=FALSE;
 
-
 -- Check purse is 'full'.
-SELECT amount_with_fee_val
-      ,amount_with_fee_frac
-      ,purse_fee_val
-      ,purse_fee_frac
+SELECT amount_with_fee
+      ,purse_fee
       ,in_reserve_quota
-  INTO my_amount.val
-      ,my_amount.frac
-      ,my_purse_fee.val
-      ,my_purse_fee.frac
-      ,my_in_reserve_quota
-  FROM exchange.purse_requests
+  INTO rval
+  FROM purse_requests pr
   WHERE purse_pub=in_purse_pub
-    AND balance_val >= amount_with_fee_val
-    AND ( (balance_frac >= amount_with_fee_frac) OR
-          (balance_val > amount_with_fee_val) );
+    AND (pr.balance).val >= (pr.amount_with_fee).val
+    AND ( (pr.balance).frac >= (pr.amount_with_fee).frac OR
+          (pr.balance).val > (pr.amount_with_fee).val );
 IF NOT FOUND
 THEN
   out_no_balance=TRUE;
   out_conflict=FALSE;
   RETURN;
 END IF;
+
+-- We use rval as workaround as we cannot select
+-- directly into the amount due to Postgres limitations.
+my_amount := rval.amount_with_fee;
+my_purse_fee := rval.purse_fee;
+my_in_reserve_quota := rval.in_reserve_quota;
+
 out_no_balance=FALSE;
 
 -- Store purse merge signature, checks for purse_pub uniqueness
@@ -228,4 +235,3 @@ END $$;
 
 COMMENT ON FUNCTION exchange_do_purse_merge(BYTEA, BYTEA, INT8, BYTEA, 
VARCHAR, BYTEA, BYTEA, INT8)
   IS 'Checks that the partner exists, the purse has not been merged with a 
different reserve and that the purse is full. If so, persists the merge data 
and either merges the purse with the reserve or marks it as ready for the 
taler-exchange-router. Caller MUST abort the transaction on failures so as to 
not persist data by accident.';
-
diff --git a/src/exchangedb/exchange_do_recoup_by_reserve.sql 
b/src/exchangedb/exchange_do_recoup_by_reserve.sql
index 6a7ea725..a4a191a4 100644
--- a/src/exchangedb/exchange_do_recoup_by_reserve.sql
+++ b/src/exchangedb/exchange_do_recoup_by_reserve.sql
@@ -25,8 +25,7 @@ RETURNS TABLE
   coin_pub             BYTEA,
   coin_sig             BYTEA,
   coin_blind           BYTEA,
-  amount_val           BIGINT,
-  amount_frac          INTEGER,
+  amount               taler_amount,
   recoup_timestamp     BIGINT
 )
 LANGUAGE plpgsql
@@ -60,16 +59,15 @@ BEGIN
              rc.coin_pub,
              rc.coin_sig,
              rc.coin_blind,
-             rc.amount_val,
-             rc.amount_frac,
+             rc.amount,
              rc.recoup_timestamp
       FROM (
-        SELECT *
+        SELECT * --FIXME: bad code, we never use '*'!
         FROM exchange.known_coins
         WHERE known_coins.coin_pub = c_pub
       ) kc
       JOIN (
-        SELECT *
+        SELECT *  --FIXME: bad code, we never use '*'!
         FROM exchange.recoup
         WHERE recoup.coin_pub = c_pub
       ) rc USING (coin_pub);
@@ -79,4 +77,3 @@ $$;
 
 COMMENT ON FUNCTION exchange_do_recoup_by_reserve
   IS 'Recoup by reserve as a function to make sure we hit only the needed 
partition and not all when joining as joins on distributed tables fetch ALL 
rows from the shards';
-
diff --git a/src/exchangedb/exchange_do_recoup_to_coin.sql 
b/src/exchangedb/exchange_do_recoup_to_coin.sql
index 5598ec20..150b62db 100644
--- a/src/exchangedb/exchange_do_recoup_to_coin.sql
+++ b/src/exchangedb/exchange_do_recoup_to_coin.sql
@@ -31,9 +31,9 @@ CREATE OR REPLACE FUNCTION exchange_do_recoup_to_coin(
 LANGUAGE plpgsql
 AS $$
 DECLARE
-  tmp_val INT8; -- amount recouped
+  rval RECORD;
 DECLARE
-  tmp_frac INT8; -- amount recouped
+  tmp taler_amount; -- amount recouped
 BEGIN
 
 -- Shards: UPDATE known_coins (by coin_pub)
@@ -41,17 +41,13 @@ BEGIN
 --         UPDATE known_coins (by coin_pub)
 --         INSERT recoup_refresh (by coin_pub)
 
-
 out_internal_failure=FALSE;
 
-
 -- Check remaining balance of the coin.
 SELECT
-   remaining_frac
-  ,remaining_val
+   remaining
  INTO
-   tmp_frac
-  ,tmp_val
+   rval
 FROM exchange.known_coins
   WHERE coin_pub=in_coin_pub;
 
@@ -62,7 +58,9 @@ THEN
   RETURN;
 END IF;
 
-IF tmp_val + tmp_frac = 0
+tmp := rval.remaining;
+
+IF tmp.val + tmp.frac = 0
 THEN
   -- Check for idempotency
   SELECT
@@ -78,29 +76,27 @@ END IF;
 -- Update balance of the coin.
 UPDATE known_coins
   SET
-     remaining_frac=0
-    ,remaining_val=0
+     remaining.val = 0
+    ,remaining.frac = 0
   WHERE coin_pub=in_coin_pub;
 
-
 -- Credit the old coin.
-UPDATE known_coins
+UPDATE known_coins kc
   SET
-    remaining_frac=remaining_frac+tmp_frac
+    remaining.frac=(kc.remaining).frac+tmp.frac
        - CASE
-         WHEN remaining_frac+tmp_frac >= 100000000
+         WHEN (kc.remaining).frac+tmp.frac >= 100000000
          THEN 100000000
          ELSE 0
          END,
-    remaining_val=remaining_val+tmp_val
+    remaining.val=(kc.remaining).val+tmp.val
        + CASE
-         WHEN remaining_frac+tmp_frac >= 100000000
+         WHEN (kc.remaining).frac+tmp.frac >= 100000000
          THEN 1
          ELSE 0
          END
   WHERE coin_pub=in_old_coin_pub;
 
-
 IF NOT FOUND
 THEN
   RAISE NOTICE 'failed to increase old coin balance from recoup';
@@ -115,8 +111,7 @@ INSERT INTO exchange.recoup_refresh
   ,known_coin_id
   ,coin_sig
   ,coin_blind
-  ,amount_val
-  ,amount_frac
+  ,amount
   ,recoup_timestamp
   ,rrc_serial
   )
@@ -125,8 +120,7 @@ VALUES
   ,in_known_coin_id
   ,in_coin_sig
   ,in_coin_blind
-  ,tmp_val
-  ,tmp_frac
+  ,tmp
   ,in_recoup_timestamp
   ,in_rrc_serial);
 
@@ -139,4 +133,3 @@ END $$;
 
 -- COMMENT ON FUNCTION exchange_do_recoup_to_coin(INT8, INT4, BYTEA, BOOLEAN, 
BOOLEAN)
 --  IS 'Executes a recoup-refresh of a coin that was obtained from a 
refresh-reveal process';
-
diff --git a/src/exchangedb/exchange_do_recoup_to_reserve.sql 
b/src/exchangedb/exchange_do_recoup_to_reserve.sql
index 71c1d51b..10ae063b 100644
--- a/src/exchangedb/exchange_do_recoup_to_reserve.sql
+++ b/src/exchangedb/exchange_do_recoup_to_reserve.sql
@@ -35,6 +35,7 @@ DECLARE
   balance taler_amount; -- current balance of the reserve
   new_balance taler_amount; -- new balance of the reserve
   reserve RECORD;
+  rval RECORD;
 BEGIN
 -- Shards: SELECT known_coins (by coin_pub)
 --         SELECT recoup      (by coin_pub)
@@ -47,11 +48,9 @@ out_internal_failure=FALSE;
 
 -- Check remaining balance of the coin.
 SELECT
-   remaining_frac
-  ,remaining_val
+   remaining
  INTO
-   tmp.frac
-  ,tmp.val
+   rval
 FROM exchange.known_coins
   WHERE coin_pub=in_coin_pub;
 
@@ -62,6 +61,8 @@ THEN
   RETURN;
 END IF;
 
+tmp := rval.remaining;
+
 IF tmp.val + tmp.frac = 0
 THEN
   -- Check for idempotency
@@ -80,12 +81,12 @@ END IF;
 -- Update balance of the coin.
 UPDATE known_coins
   SET
-     remaining_frac=0
-    ,remaining_val=0
+     remaining.val = 0
+    ,remaining.frac = 0
   WHERE coin_pub=in_coin_pub;
 
 -- Get current balance
-SELECT *
+SELECT current_balance
   INTO reserve
   FROM reserves
  WHERE reserve_pub=in_reserve_pub;
@@ -127,8 +128,7 @@ INSERT INTO exchange.recoup
   (coin_pub
   ,coin_sig
   ,coin_blind
-  ,amount_val
-  ,amount_frac
+  ,amount
   ,recoup_timestamp
   ,reserve_out_serial_id
   )
@@ -136,8 +136,7 @@ VALUES
   (in_coin_pub
   ,in_coin_sig
   ,in_coin_blind
-  ,tmp.val
-  ,tmp.frac
+  ,tmp
   ,in_recoup_timestamp
   ,in_reserve_out_serial_id);
 
@@ -149,6 +148,3 @@ END $$;
 
 -- COMMENT ON FUNCTION exchange_do_recoup_to_reserve(INT8, INT4, BYTEA, 
BOOLEAN, BOOLEAN)
 --  IS 'Executes a recoup of a coin that was withdrawn from a reserve';
-
-
-
diff --git a/src/exchangedb/exchange_do_refund.sql 
b/src/exchangedb/exchange_do_refund.sql
index ceaabfe1..7cb50e9f 100644
--- a/src/exchangedb/exchange_do_refund.sql
+++ b/src/exchangedb/exchange_do_refund.sql
@@ -15,12 +15,9 @@
 --
 
 CREATE OR REPLACE FUNCTION exchange_do_refund(
-  IN in_amount_with_fee_val INT8,
-  IN in_amount_with_fee_frac INT4,
-  IN in_amount_val INT8,
-  IN in_amount_frac INT4,
-  IN in_deposit_fee_val INT8,
-  IN in_deposit_fee_frac INT4,
+  IN in_amount_with_fee taler_amount,
+  IN in_amount taler_amount,
+  IN in_deposit_fee taler_amount,
   IN in_h_contract_terms BYTEA,
   IN in_rtransaction_id INT8,
   IN in_deposit_shard INT8,
@@ -39,11 +36,11 @@ DECLARE
 DECLARE
   tmp_val INT8; -- total amount refunded
 DECLARE
-  tmp_frac INT8; -- total amount refunded
+  tmp_frac INT8; -- total amount refunded, large fraction to deal with 
overflows!
 DECLARE
-  deposit_val INT8; -- amount that was originally deposited
+  tmp taler_amount; -- total amount refunded, normalized
 DECLARE
-  deposit_frac INT8; -- amount that was originally deposited
+  deposit taler_amount; -- amount that was originally deposited
 BEGIN
 -- Shards: SELECT deposits (coin_pub, shard, h_contract_terms, merchant_pub)
 --         INSERT refunds (by coin_pub, rtransaction_id) ON CONFLICT DO NOTHING
@@ -52,15 +49,15 @@ BEGIN
 
 SELECT
    deposit_serial_id
-  ,amount_with_fee_val
-  ,amount_with_fee_frac
+  ,(dep.amount_with_fee).val
+  ,(dep.amount_with_fee).frac
   ,done
 INTO
    dsi
-  ,deposit_val
-  ,deposit_frac
+  ,deposit.val
+  ,deposit.frac
   ,out_gone
-FROM exchange.deposits
+FROM exchange.deposits dep
  WHERE coin_pub=in_coin_pub
   AND shard=in_deposit_shard
   AND merchant_pub=in_merchant_pub
@@ -81,16 +78,15 @@ INSERT INTO exchange.refunds
   ,coin_pub
   ,merchant_sig
   ,rtransaction_id
-  ,amount_with_fee_val
-  ,amount_with_fee_frac
+  ,amount_with_fee
   )
   VALUES
   (dsi
   ,in_coin_pub
   ,in_merchant_sig
   ,in_rtransaction_id
-  ,in_amount_with_fee_val
-  ,in_amount_with_fee_frac)
+  ,in_amount_with_fee
+  )
   ON CONFLICT DO NOTHING;
 
 IF NOT FOUND
@@ -105,8 +101,7 @@ THEN
    WHERE coin_pub=in_coin_pub
      AND deposit_serial_id=dsi
      AND rtransaction_id=in_rtransaction_id
-     AND amount_with_fee_val=in_amount_with_fee_val
-     AND amount_with_fee_frac=in_amount_with_fee_frac;
+     AND amount_with_fee=in_amount_with_fee;
 
   IF NOT FOUND
   THEN
@@ -136,12 +131,12 @@ END IF;
 
 -- Check refund balance invariant.
 SELECT
-   SUM(amount_with_fee_val) -- overflow here is not plausible
-  ,SUM(CAST(amount_with_fee_frac AS INT8)) -- compute using 64 bits
+   SUM((refunds.amount_with_fee).val) -- overflow here is not plausible
+  ,SUM(CAST((refunds.amount_with_fee).frac AS INT8)) -- compute using 64 bits
   INTO
    tmp_val
   ,tmp_frac
-  FROM exchange.refunds
+  FROM exchange.refunds refunds
   WHERE coin_pub=in_coin_pub
     AND deposit_serial_id=dsi;
 IF tmp_val IS NULL
@@ -154,15 +149,15 @@ THEN
 END IF;
 
 -- Normalize result before continuing
-tmp_val = tmp_val + tmp_frac / 100000000;
-tmp_frac = tmp_frac % 100000000;
+tmp.val = tmp_val + tmp_frac / 100000000;
+tmp.frac = tmp_frac % 100000000;
 
 -- Actually check if the deposits are sufficient for the refund. Verbosely. ;-)
-IF (tmp_val < deposit_val)
+IF (tmp.val < deposit.val)
 THEN
   out_refund_ok=TRUE;
 ELSE
-  IF (tmp_val = deposit_val) AND (tmp_frac <= deposit_frac)
+  IF (tmp.val = deposit.val) AND (tmp.frac <= deposit.frac)
   THEN
     out_refund_ok=TRUE;
   ELSE
@@ -170,42 +165,39 @@ ELSE
   END IF;
 END IF;
 
-IF (tmp_val = deposit_val) AND (tmp_frac = deposit_frac)
+IF (tmp.val = deposit.val) AND (tmp.frac = deposit.frac)
 THEN
   -- Refunds have reached the full value of the original
   -- deposit. Also refund the deposit fee.
-  in_amount_frac = in_amount_frac + in_deposit_fee_frac;
-  in_amount_val = in_amount_val + in_deposit_fee_val;
+  in_amount.frac = in_amount.frac + in_deposit_fee.frac;
+  in_amount.val = in_amount.val + in_deposit_fee.val;
 
   -- Normalize result before continuing
-  in_amount_val = in_amount_val + in_amount_frac / 100000000;
-  in_amount_frac = in_amount_frac % 100000000;
+  in_amount.val = in_amount.val + in_amount.frac / 100000000;
+  in_amount.frac = in_amount.frac % 100000000;
 END IF;
 
 -- Update balance of the coin.
-UPDATE known_coins
+UPDATE known_coins kc
   SET
-    remaining_frac=remaining_frac+in_amount_frac
+    remaining.frac=(kc.remaining).frac+in_amount.frac
        - CASE
-         WHEN remaining_frac+in_amount_frac >= 100000000
+         WHEN (kc.remaining).frac+in_amount.frac >= 100000000
          THEN 100000000
          ELSE 0
          END,
-    remaining_val=remaining_val+in_amount_val
+    remaining.val=(kc.remaining).val+in_amount.val
        + CASE
-         WHEN remaining_frac+in_amount_frac >= 100000000
+         WHEN (kc.remaining).frac+in_amount.frac >= 100000000
          THEN 1
          ELSE 0
          END
   WHERE coin_pub=in_coin_pub;
 
-
 out_conflict=FALSE;
 out_not_found=FALSE;
 
 END $$;
 
--- COMMENT ON FUNCTION exchange_do_refund(INT8, INT4, BYTEA, BOOLEAN, BOOLEAN)
+-- COMMENT ON FUNCTION exchange_do_refund(taler_amount, BYTEA, BOOLEAN, 
BOOLEAN)
 --  IS 'Executes a refund operation, checking that the corresponding deposit 
was sufficient to cover the refunded amount';
-
-
diff --git a/src/exchangedb/exchange_do_refund_by_coin.sql 
b/src/exchangedb/exchange_do_refund_by_coin.sql
index ee00e2b5..d5f99e6a 100644
--- a/src/exchangedb/exchange_do_refund_by_coin.sql
+++ b/src/exchangedb/exchange_do_refund_by_coin.sql
@@ -13,11 +13,7 @@
 -- You should have received a copy of the GNU General Public License along with
 -- TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 --
-/*DROP FUNCTION exchange_do_refund_by_coin(
-  IN in_coin_pub BYTEA,
-  IN in_merchant_pub BYTEA,
-  IN in_h_contract BYTEA
-);*/
+
 CREATE OR REPLACE FUNCTION exchange_do_refund_by_coin(
   IN in_coin_pub BYTEA,
   IN in_merchant_pub BYTEA,
@@ -30,8 +26,7 @@ DECLARE
   curs CURSOR
   FOR
   SELECT
-    amount_with_fee_val
-   ,amount_with_fee_frac
+    amount_with_fee
    ,deposit_serial_id
   FROM refunds
   WHERE coin_pub=in_coin_pub;
@@ -44,8 +39,7 @@ LOOP
     EXIT WHEN NOT FOUND;
     RETURN QUERY
       SELECT
-        i.amount_with_fee_val
-       ,i.amount_with_fee_frac
+        i.amount_with_fee
        FROM deposits
        WHERE
          coin_pub=in_coin_pub
@@ -56,15 +50,14 @@ END LOOP;
 CLOSE curs;
 END $$;
 
-/*RETURNS TABLE(amount_with_fee_val INT8, amount_with_fee_frac INT4)
+/*RETURNS TABLE(amount_with_fee taler_amount)
 LANGUAGE plpgsql
 AS $$
 DECLARE
   curs CURSOR
   FOR
   SELECT
-    r.amount_with_fee_val
-   ,r.amount_with_fee_frac
+    r.amount_with_fee
    ,r.deposit_serial_id
   FROM refunds r
   WHERE r.coin_pub=in_coin_pub;
@@ -78,8 +71,7 @@ LOOP
     THEN
       RETURN QUERY
       SELECT
-        i.amount_with_fee_val
-       ,i.amount_with_fee_frac
+        i.amount_with_fee
        FROM deposits
        WHERE
          merchant_pub=in_merchant_pub
diff --git a/src/exchangedb/exchange_do_reserve_open_deposit.sql 
b/src/exchangedb/exchange_do_reserve_open_deposit.sql
index 72512270..aa6f86a9 100644
--- a/src/exchangedb/exchange_do_reserve_open_deposit.sql
+++ b/src/exchangedb/exchange_do_reserve_open_deposit.sql
@@ -21,8 +21,7 @@ CREATE OR REPLACE FUNCTION exchange_do_reserve_open_deposit(
   IN in_coin_sig BYTEA,
   IN in_reserve_sig BYTEA,
   IN in_reserve_pub BYTEA,
-  IN in_coin_total_val INT8,
-  IN in_coin_total_frac INT4,
+  IN in_coin_total taler_amount,
   OUT out_insufficient_funds BOOLEAN)
 LANGUAGE plpgsql
 AS $$
@@ -33,16 +32,15 @@ INSERT INTO exchange.reserves_open_deposits
   ,reserve_pub
   ,coin_pub
   ,coin_sig
-  ,contribution_val
-  ,contribution_frac
+  ,contribution
   )
   VALUES
   (in_reserve_sig
   ,in_reserve_pub
   ,in_coin_pub
   ,in_coin_sig
-  ,in_coin_total_val
-  ,in_coin_total_frac)
+  ,in_coin_total
+  )
   ON CONFLICT DO NOTHING;
 
 IF NOT FOUND
@@ -54,24 +52,24 @@ END IF;
 
 
 -- Check and update balance of the coin.
-UPDATE exchange.known_coins
+UPDATE exchange.known_coins kc
   SET
-    remaining_frac=remaining_frac-in_coin_total_frac
+    remaining.frac=(kc.remaining).frac-in_coin_total.frac
        + CASE
-         WHEN remaining_frac < in_coin_total_frac
+         WHEN (kc.remaining).frac < in_coin_total.frac
          THEN 100000000
          ELSE 0
          END,
-    remaining_val=remaining_val-in_coin_total_val
+    remaining.val=(kc.remaining).val-in_coin_total.val
        - CASE
-         WHEN remaining_frac < in_coin_total_frac
+         WHEN (kc.remaining).frac < in_coin_total.frac
          THEN 1
          ELSE 0
          END
   WHERE coin_pub=in_coin_pub
-    AND ( (remaining_val > in_coin_total_val) OR
-          ( (remaining_frac >= in_coin_total_frac) AND
-            (remaining_val >= in_coin_total_val) ) );
+    AND ( ((kc.remaining).val > in_coin_total.val) OR
+          ( ((kc.remaining).frac >= in_coin_total.frac) AND
+            ((kc.remaining).val >= in_coin_total.val) ) );
 
 IF NOT FOUND
 THEN
@@ -84,4 +82,3 @@ END IF;
 out_insufficient_funds=FALSE;
 
 END $$;
-
diff --git a/src/exchangedb/exchange_do_reserves_in_insert.sql 
b/src/exchangedb/exchange_do_reserves_in_insert.sql
index fcf8ef4c..b5876ba3 100644
--- a/src/exchangedb/exchange_do_reserves_in_insert.sql
+++ b/src/exchangedb/exchange_do_reserves_in_insert.sql
@@ -56,16 +56,14 @@ BEGIN
   INSERT INTO reserves_in
     (reserve_pub
     ,wire_reference
-    ,credit_val
-    ,credit_frac
+    ,credit
     ,exchange_account_section
     ,wire_source_h_payto
     ,execution_date)
     VALUES
     (in_reserve_pub
     ,in_wire_ref
-    ,in_credit.val
-    ,in_credit.frac
+    ,in_credit
     ,in_exchange_account_name
     ,in_wire_source_h_payto
     ,in_execution_date)
@@ -181,16 +179,14 @@ BEGIN
     INSERT INTO reserves_in
       (reserve_pub
       ,wire_reference
-      ,credit_val
-      ,credit_frac
+      ,credit
       ,exchange_account_section
       ,wire_source_h_payto
       ,execution_date)
       VALUES
       (in0_reserve_pub
       ,in0_wire_ref
-      ,in0_credit.val
-      ,in0_credit.frac
+      ,in0_credit
       ,in0_exchange_account_name
       ,in0_wire_source_h_payto
       ,in0_execution_date),
@@ -394,16 +390,14 @@ BEGIN
     INSERT INTO reserves_in
       (reserve_pub
       ,wire_reference
-      ,credit_val
-      ,credit_frac
+      ,credit
       ,exchange_account_section
       ,wire_source_h_payto
       ,execution_date)
       VALUES
       (in0_reserve_pub
       ,in0_wire_ref
-      ,in0_credit.val
-      ,in0_credit.frac
+      ,in0_credit
       ,in0_exchange_account_name
       ,in0_wire_source_h_payto
       ,in0_execution_date),
@@ -750,16 +744,14 @@ BEGIN
     INSERT INTO reserves_in
       (reserve_pub
       ,wire_reference
-      ,credit_val
-      ,credit_frac
+      ,credit
       ,exchange_account_section
       ,wire_source_h_payto
       ,execution_date)
       VALUES
       (in0_reserve_pub
       ,in0_wire_ref
-      ,in0_credit.val
-      ,in0_credit.frac
+      ,in0_credit
       ,in0_exchange_account_name
       ,in0_wire_source_h_payto
       ,in0_execution_date),
@@ -927,8 +919,7 @@ CREATE OR REPLACE FUNCTION 
exchange_do_array_reserves_insert(
   IN in_reserve_expiration INT8,
   IN ina_reserve_pub BYTEA[],
   IN ina_wire_ref INT8[],
-  IN ina_credit_val INT8[],
-  IN ina_credit_frac INT4[],
+  IN ina_credit taler_amount[],
   IN ina_exchange_account_name VARCHAR[],
   IN ina_execution_date INT8[],
   IN ina_wire_source_h_payto BYTEA[],
@@ -960,8 +951,7 @@ BEGIN
     SELECT
       reserve_pub
      ,wire_ref
-     ,credit_val
-     ,credit_frac
+     ,credit
      ,exchange_account_name
      ,execution_date
      ,wire_source_h_payto
@@ -970,8 +960,7 @@ BEGIN
     FROM
       UNNEST (ina_reserve_pub) AS reserve_pub
      ,UNNEST (ina_wire_ref) AS wire_ref
-     ,UNNEST (ina_credit_val) AS credit_val
-     ,UNNEST (ina_credit_frac) AS credit_frac
+     ,UNNEST (ina_credit) AS credit
      ,UNNEST (ina_exchange_account_name) AS exchange_account_name
      ,UNNEST (ina_execution_date) AS execution_date
      ,UNNEST (ina_wire_source_h_payto) AS wire_source_h_payto
@@ -979,14 +968,12 @@ BEGIN
   LOOP
     INSERT INTO reserves
       (reserve_pub
-      ,current_balance_val
-      ,current_balance_frac
+      ,current_balance
       ,expiration_date
       ,gc_date
     ) VALUES (
       i.reserve_pub
-     ,i.credit_val
-     ,i.credit_frac
+     ,i.credit
      ,in_reserve_expiration
      ,in_gc_date
     )
@@ -998,16 +985,14 @@ BEGIN
     INSERT INTO reserves_in
       (reserve_pub
       ,wire_reference
-      ,credit_val
-      ,credit_frac
+      ,credit
       ,exchange_account_section
       ,wire_source_h_payto
       ,execution_date
     ) VALUES (
       i.reserve_pub
      ,i.wire_reference
-     ,i.credit_val
-     ,i.credit_frac
+     ,i.credit
      ,i.exchange_account_section
      ,i.wire_source_h_payto
      ,i.execution_date
diff --git a/src/exchangedb/exchange_do_withdraw.sql 
b/src/exchangedb/exchange_do_withdraw.sql
index 60a63e67..c25267b7 100644
--- a/src/exchangedb/exchange_do_withdraw.sql
+++ b/src/exchangedb/exchange_do_withdraw.sql
@@ -114,8 +114,7 @@ INSERT INTO exchange.reserves_out
   ,reserve_uuid
   ,reserve_sig
   ,execution_date
-  ,amount_with_fee_val
-  ,amount_with_fee_frac)
+  ,amount_with_fee)
 VALUES
   (h_coin_envelope
   ,denom_serial
@@ -123,8 +122,7 @@ VALUES
   ,ruuid
   ,reserve_sig
   ,now
-  ,amount.val
-  ,amount.frac)
+  ,amount)
 ON CONFLICT DO NOTHING;
 
 IF NOT FOUND
@@ -213,4 +211,3 @@ END $$;
 
 COMMENT ON FUNCTION exchange_do_withdraw(BYTEA, taler_amount, BYTEA, BYTEA, 
BYTEA, BYTEA, BYTEA, INT8, INT8, BOOLEAN)
   IS 'Checks whether the reserve has sufficient balance for a withdraw 
operation (or the request is repeated and was previously approved) and if the 
age requirements are formally met.  If so updates the database with the result';
-
diff --git a/src/exchangedb/pg_add_denomination_key.c 
b/src/exchangedb/pg_add_denomination_key.c
index fa6d92ed..48d882c9 100644
--- a/src/exchangedb/pg_add_denomination_key.c
+++ b/src/exchangedb/pg_add_denomination_key.c
@@ -43,11 +43,16 @@ TEH_PG_add_denomination_key (
     GNUNET_PQ_query_param_timestamp (&meta->expire_withdraw),
     GNUNET_PQ_query_param_timestamp (&meta->expire_deposit),
     GNUNET_PQ_query_param_timestamp (&meta->expire_legal),
-    TALER_PQ_query_param_amount (&meta->value),
-    TALER_PQ_query_param_amount (&meta->fees.withdraw),
-    TALER_PQ_query_param_amount (&meta->fees.deposit),
-    TALER_PQ_query_param_amount (&meta->fees.refresh),
-    TALER_PQ_query_param_amount (&meta->fees.refund),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &meta->value),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &meta->fees.withdraw),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &meta->fees.deposit),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &meta->fees.refresh),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &meta->fees.refund),
     GNUNET_PQ_query_param_uint32 (&meta->age_mask.bits),
     GNUNET_PQ_query_param_end
   };
@@ -56,8 +61,6 @@ TEH_PG_add_denomination_key (
   GNUNET_assert (GNUNET_YES ==
                  TALER_denom_fee_check_currency (meta->value.currency,
                                                  &meta->fees));
-  /* Used in #postgres_insert_denomination_info() and
-   #postgres_add_denomination_key() */
   PREPARE (pg,
            "denomination_insert",
            "INSERT INTO denominations "
@@ -68,20 +71,15 @@ TEH_PG_add_denomination_key (
            ",expire_withdraw"
            ",expire_deposit"
            ",expire_legal"
-           ",coin_val"                                                /* value 
of this denom */
-           ",coin_frac"                                                /* 
fractional value of this denom */
-           ",fee_withdraw_val"
-           ",fee_withdraw_frac"
-           ",fee_deposit_val"
-           ",fee_deposit_frac"
-           ",fee_refresh_val"
-           ",fee_refresh_frac"
-           ",fee_refund_val"
-           ",fee_refund_frac"
+           ",coin"     /* value of this denom */
+           ",fee_withdraw"
+           ",fee_deposit"
+           ",fee_refresh"
+           ",fee_refund"
            ",age_mask"
            ") VALUES "
            "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
-           " $11, $12, $13, $14, $15, $16, $17, $18);");
+           " $11, $12, $13);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "denomination_insert",
                                              iparams);
diff --git a/src/exchangedb/pg_add_policy_fulfillment_proof.c 
b/src/exchangedb/pg_add_policy_fulfillment_proof.c
index 103de7ad..5ba18f47 100644
--- a/src/exchangedb/pg_add_policy_fulfillment_proof.c
+++ b/src/exchangedb/pg_add_policy_fulfillment_proof.c
@@ -94,7 +94,7 @@ TEH_PG_add_policy_fulfillment_proof (
       GNUNET_PQ_result_spec_end
     };
 
-
+    // FIXME: where do we prepare this statement!??
     qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
                                                    
"insert_proof_into_policy_fulfillments",
                                                    params,
@@ -112,14 +112,19 @@ TEH_PG_add_policy_fulfillment_proof (
       struct GNUNET_PQ_QueryParam params[] = {
         GNUNET_PQ_query_param_auto_from_type (&pos->hash_code),
         GNUNET_PQ_query_param_timestamp (&pos->deadline),
-        TALER_PQ_query_param_amount (&pos->commitment),
-        TALER_PQ_query_param_amount (&pos->accumulated_total),
-        TALER_PQ_query_param_amount (&pos->policy_fee),
-        TALER_PQ_query_param_amount (&pos->transferable_amount),
+        TALER_PQ_query_param_amount_tuple (pg->conn,
+                                           &pos->commitment),
+        TALER_PQ_query_param_amount_tuple (pg->conn,
+                                           &pos->accumulated_total),
+        TALER_PQ_query_param_amount_tuple (pg->conn,
+                                           &pos->policy_fee),
+        TALER_PQ_query_param_amount_tuple (pg->conn,
+                                           &pos->transferable_amount),
         GNUNET_PQ_query_param_auto_from_type (&pos->fulfillment_state),
         GNUNET_PQ_query_param_end
       };
 
+      // FIXME: where do we prepare this statement!??
       qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                                "update_policy_details",
                                                params);
diff --git a/src/exchangedb/pg_aggregate.c b/src/exchangedb/pg_aggregate.c
index 76d0adec..82f73192 100644
--- a/src/exchangedb/pg_aggregate.c
+++ b/src/exchangedb/pg_aggregate.c
@@ -62,12 +62,10 @@ TEH_PG_aggregate (
            "   RETURNING"
            "     deposit_serial_id"
            "    ,coin_pub"
-           "    ,amount_with_fee_val AS amount_val"
-           "    ,amount_with_fee_frac AS amount_frac)"
+           "    ,amount_with_fee AS amount)"
            " ,ref AS (" /* find applicable refunds -- NOTE: may do a full join 
on the master, maybe find a left-join way to integrate with query above to push 
it to the shards? */
            "  SELECT"
-           "    amount_with_fee_val AS refund_val"
-           "   ,amount_with_fee_frac AS refund_frac"
+           "    amount_with_fee AS refund"
            "   ,coin_pub"
            "   ,deposit_serial_id" /* theoretically, coin could be in multiple 
refunded transactions */
            "    FROM refunds"
@@ -75,8 +73,8 @@ TEH_PG_aggregate (
            "     AND deposit_serial_id IN (SELECT deposit_serial_id FROM dep))"
            " ,ref_by_coin AS (" /* total up refunds by coin */
            "  SELECT"
-           "    SUM(refund_val) AS sum_refund_val"
-           "   ,SUM(refund_frac) AS sum_refund_frac"
+           "    SUM((ref.refund).val) AS sum_refund_val"
+           "   ,SUM((ref.refund).frac) AS sum_refund_frac"
            "   ,coin_pub"
            "   ,deposit_serial_id" /* theoretically, coin could be in multiple 
refunded transactions */
            "    FROM ref"
@@ -94,13 +92,12 @@ TEH_PG_aggregate (
            "    FROM norm_ref_by_coin norm"
            "    JOIN dep"
            "      ON (norm.coin_pub = dep.coin_pub"
-           "      AND norm.deposit_serial_id = dep.deposit_Serial_id"
-           "      AND norm.norm_refund_val = dep.amount_val"
-           "      AND norm.norm_refund_frac = dep.amount_frac))"
+           "      AND norm.deposit_serial_id = dep.deposit_serial_id"
+           "      AND norm.norm_refund_val = (dep.amount).val"
+           "      AND norm.norm_refund_frac = (dep.amount).frac))"
            " ,fees AS (" /* find deposit fees for not fully refunded deposits 
*/
            "  SELECT"
-           "    denom.fee_deposit_val AS fee_val"
-           "   ,denom.fee_deposit_frac AS fee_frac"
+           "    denom.fee_deposit AS fee"
            "   ,cs.deposit_serial_id" /* ensures we get the fee for each coin, 
not once per denomination */
            "    FROM dep cs"
            "    JOIN known_coins kc" /* NOTE: may do a full join on the 
master, maybe find a left-join way to integrate with query above to push it to 
the shards? */
@@ -115,12 +112,12 @@ TEH_PG_aggregate (
            "    SELECT deposit_serial_id,$4"
            "      FROM dep)"
            "SELECT" /* calculate totals (deposits, refunds and fees) */
-           "  CAST(COALESCE(SUM(dep.amount_val),0) AS INT8) AS 
sum_deposit_value" /* cast needed, otherwise we get NUMBER */
-           " ,COALESCE(SUM(dep.amount_frac),0) AS sum_deposit_fraction" /* SUM 
over INT returns INT8 */
-           " ,CAST(COALESCE(SUM(ref.refund_val),0) AS INT8) AS 
sum_refund_value"
-           " ,COALESCE(SUM(ref.refund_frac),0) AS sum_refund_fraction"
-           " ,CAST(COALESCE(SUM(fees.fee_val),0) AS INT8) AS sum_fee_value"
-           " ,COALESCE(SUM(fees.fee_frac),0) AS sum_fee_fraction"
+           "  CAST(COALESCE(SUM((dep.amount).val),0) AS INT8) AS 
sum_deposit_value" /* cast needed, otherwise we get NUMBER */
+           " ,COALESCE(SUM((dep.amount).frac),0) AS sum_deposit_fraction" /* 
SUM over INT returns INT8 */
+           " ,CAST(COALESCE(SUM((ref.refund).val),0) AS INT8) AS 
sum_refund_value"
+           " ,COALESCE(SUM((ref.refund).frac),0) AS sum_refund_fraction"
+           " ,CAST(COALESCE(SUM((fees.fee).val),0) AS INT8) AS sum_fee_value"
+           " ,COALESCE(SUM((fees.fee).frac),0) AS sum_fee_fraction"
            " FROM dep "
            "   FULL OUTER JOIN ref ON (FALSE)"    /* We just want all sums */
            "   FULL OUTER JOIN fees ON (FALSE);");
diff --git a/src/exchangedb/pg_create_aggregation_transient.c 
b/src/exchangedb/pg_create_aggregation_transient.c
index 80fba8bf..5c58c696 100644
--- a/src/exchangedb/pg_create_aggregation_transient.c
+++ b/src/exchangedb/pg_create_aggregation_transient.c
@@ -38,7 +38,8 @@ TEH_PG_create_aggregation_transient (
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
-    TALER_PQ_query_param_amount (total),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       total),
     GNUNET_PQ_query_param_auto_from_type (merchant_pub),
     GNUNET_PQ_query_param_auto_from_type (h_payto),
     GNUNET_PQ_query_param_uint64 (&kyc_requirement_row),
@@ -46,18 +47,17 @@ TEH_PG_create_aggregation_transient (
     GNUNET_PQ_query_param_auto_from_type (wtid),
     GNUNET_PQ_query_param_end
   };
-  /* Used in #postgres_create_aggregation_transient() */
+
   PREPARE (pg,
            "create_aggregation_transient",
            "INSERT INTO aggregation_transient"
-           " (amount_val"
-           " ,amount_frac"
+           " (amount"
            " ,merchant_pub"
            " ,wire_target_h_payto"
            " ,legitimization_requirement_serial_id"
            " ,exchange_account_section"
            " ,wtid_raw)"
-           " VALUES ($1, $2, $3, $4, $5, $6, $7);");
+           " VALUES ($1, $2, $3, $4, $5, $6);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "create_aggregation_transient",
                                              params);
diff --git a/src/exchangedb/pg_do_deposit.c b/src/exchangedb/pg_do_deposit.c
index f3d0856a..3120232b 100644
--- a/src/exchangedb/pg_do_deposit.c
+++ b/src/exchangedb/pg_do_deposit.c
@@ -41,7 +41,8 @@ TEH_PG_do_deposit (
   struct PostgresClosure *pg = cls;
   uint64_t deposit_shard = TEH_PG_compute_shard (&deposit->merchant_pub);
   struct GNUNET_PQ_QueryParam params[] = {
-    TALER_PQ_query_param_amount (&deposit->amount_with_fee),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &deposit->amount_with_fee),
     GNUNET_PQ_query_param_auto_from_type (&deposit->h_contract_terms),
     GNUNET_PQ_query_param_auto_from_type (&deposit->wire_salt),
     GNUNET_PQ_query_param_timestamp (&deposit->timestamp),
@@ -78,7 +79,7 @@ TEH_PG_do_deposit (
            ",out_balance_ok AS balance_ok"
            ",out_conflict AS conflicted"
            " FROM exchange_do_deposit"
-           " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17);");
+           " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);");
   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
                                                    "call_deposit",
                                                    params,
diff --git a/src/exchangedb/pg_do_melt.c b/src/exchangedb/pg_do_melt.c
index 40a54d43..0a827acc 100644
--- a/src/exchangedb/pg_do_melt.c
+++ b/src/exchangedb/pg_do_melt.c
@@ -40,7 +40,8 @@ TEH_PG_do_melt (
     NULL == rms
     ? GNUNET_PQ_query_param_null ()
     : GNUNET_PQ_query_param_auto_from_type (rms),
-    TALER_PQ_query_param_amount (&refresh->amount_with_fee),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &refresh->amount_with_fee),
     GNUNET_PQ_query_param_auto_from_type (&refresh->rc),
     GNUNET_PQ_query_param_auto_from_type (&refresh->coin.coin_pub),
     GNUNET_PQ_query_param_auto_from_type (&refresh->coin_sig),
@@ -63,7 +64,6 @@ TEH_PG_do_melt (
   };
   enum GNUNET_DB_QueryStatus qs;
 
-  /* Used in #postgres_do_melt() to melt a coin. */
   PREPARE (pg,
            "call_melt",
            "SELECT "
@@ -71,7 +71,7 @@ TEH_PG_do_melt (
            ",out_zombie_bad AS zombie_required"
            ",out_noreveal_index AS noreveal_index"
            " FROM exchange_do_melt"
-           " ($1,$2,$3,$4,$5,$6,$7,$8,$9);");
+           " ($1,$2,$3,$4,$5,$6,$7,$8);");
   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
                                                  "call_melt",
                                                  params,
diff --git a/src/exchangedb/pg_do_refund.c b/src/exchangedb/pg_do_refund.c
index 0b9665c4..887b610b 100644
--- a/src/exchangedb/pg_do_refund.c
+++ b/src/exchangedb/pg_do_refund.c
@@ -25,6 +25,8 @@
 #include "pg_do_refund.h"
 #include "pg_helper.h"
 #include "pg_compute_shard.h"
+
+
 enum GNUNET_DB_QueryStatus
 TEH_PG_do_refund (
   void *cls,
@@ -40,9 +42,12 @@ TEH_PG_do_refund (
   uint64_t deposit_shard = TEH_PG_compute_shard 
(&refund->details.merchant_pub);
   struct TALER_Amount amount_without_fee;
   struct GNUNET_PQ_QueryParam params[] = {
-    TALER_PQ_query_param_amount (&refund->details.refund_amount),
-    TALER_PQ_query_param_amount (&amount_without_fee),
-    TALER_PQ_query_param_amount (deposit_fee),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &refund->details.refund_amount),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &amount_without_fee),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       deposit_fee),
     GNUNET_PQ_query_param_auto_from_type (&refund->details.h_contract_terms),
     GNUNET_PQ_query_param_uint64 (&refund->details.rtransaction_id),
     GNUNET_PQ_query_param_uint64 (&deposit_shard),
@@ -72,7 +77,6 @@ TEH_PG_do_refund (
     GNUNET_break (0);
     return GNUNET_DB_STATUS_HARD_ERROR;
   }
-  /* Used in #postgres_do_refund() to refund a deposit. */
   PREPARE (pg,
            "call_refund",
            "SELECT "
@@ -81,8 +85,7 @@ TEH_PG_do_refund (
            ",out_gone AS gone"
            ",out_conflict AS conflict"
            " FROM exchange_do_refund"
-           " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13);");
-
+           " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);");
   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
                                                    "call_refund",
                                                    params,
diff --git a/src/exchangedb/pg_ensure_coin_known.c 
b/src/exchangedb/pg_ensure_coin_known.c
index 721123fd..34613575 100644
--- a/src/exchangedb/pg_ensure_coin_known.c
+++ b/src/exchangedb/pg_ensure_coin_known.c
@@ -60,9 +60,8 @@ TEH_PG_ensure_coin_known (void *cls,
       &is_age_hash_null),
     GNUNET_PQ_result_spec_end
   };
-  /* Used in #postgres_insert_known_coin() to store the denomination public
-     key and signature for a coin known to the exchange.
 
+  /*
      See also:
      
https://stackoverflow.com/questions/34708509/how-to-use-returning-with-on-conflict-in-postgresql/37543015#37543015
   */
@@ -70,13 +69,11 @@ TEH_PG_ensure_coin_known (void *cls,
            "insert_known_coin",
            "WITH dd"
            "  (denominations_serial"
-           "  ,coin_val"
-           "  ,coin_frac"
+           "  ,coin"
            "  ) AS ("
            "    SELECT "
            "       denominations_serial"
-           "      ,coin_val"
-           "      ,coin_frac"
+           "      ,coin"
            "        FROM denominations"
            "        WHERE denom_pub_hash=$2"
            "  ), input_rows"
@@ -88,15 +85,13 @@ TEH_PG_ensure_coin_known (void *cls,
            "  ,denominations_serial"
            "  ,age_commitment_hash"
            "  ,denom_sig"
-           "  ,remaining_val"
-           "  ,remaining_frac"
+           "  ,remaining"
            "  ) SELECT "
            "     $1"
            "    ,denominations_serial"
            "    ,$3"
            "    ,$4"
-           "    ,coin_val"
-           "    ,coin_frac"
+           "    ,coin"
            "  FROM dd"
            "  ON CONFLICT DO NOTHING" /* CONFLICT on (coin_pub) */
            "  RETURNING "
diff --git a/src/exchangedb/pg_find_aggregation_transient.c 
b/src/exchangedb/pg_find_aggregation_transient.c
index ecc6362c..b931188a 100644
--- a/src/exchangedb/pg_find_aggregation_transient.c
+++ b/src/exchangedb/pg_find_aggregation_transient.c
@@ -128,12 +128,11 @@ TEH_PG_find_aggregation_transient (
     .pg = pg,
     .status = GNUNET_OK
   };
-  /* Used in #postgres_find_aggregation_transient() */
+
   PREPARE (pg,
            "find_transient_aggregations",
            "SELECT"
-           "  amount_val"
-           " ,amount_frac"
+           "  amount"
            " ,wtid_raw"
            " ,merchant_pub"
            " ,payto_uri"
diff --git a/src/exchangedb/pg_get_coin_transactions.c 
b/src/exchangedb/pg_get_coin_transactions.c
index f24c9be4..807c4d8f 100644
--- a/src/exchangedb/pg_get_coin_transactions.c
+++ b/src/exchangedb/pg_get_coin_transactions.c
@@ -726,10 +726,8 @@ TEH_PG_get_coin_transactions (
   PREPARE (pg,
            "get_deposit_with_coin_pub",
            "SELECT"
-           " dep.amount_with_fee_val"
-           ",dep.amount_with_fee_frac"
-           ",denoms.fee_deposit_val"
-           ",denoms.fee_deposit_frac"
+           " dep.amount_with_fee"
+           ",denoms.fee_deposit"
            ",denoms.denom_pub_hash"
            ",kc.age_commitment_hash"
            ",dep.wallet_timestamp"
@@ -755,11 +753,9 @@ TEH_PG_get_coin_transactions (
            "SELECT"
            " rc"
            ",old_coin_sig"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
+           ",amount_with_fee"
            ",denoms.denom_pub_hash"
-           ",denoms.fee_refresh_val"
-           ",denoms.fee_refresh_frac"
+           ",denoms.fee_refresh"
            ",kc.age_commitment_hash"
            ",melt_serial_id"
            " FROM refresh_commitments"
@@ -772,10 +768,8 @@ TEH_PG_get_coin_transactions (
            "get_purse_deposit_by_coin_pub",
            "SELECT"
            " partner_base_url"
-           ",pd.amount_with_fee_val"
-           ",pd.amount_with_fee_frac"
-           ",denoms.fee_deposit_val"
-           ",denoms.fee_deposit_frac"
+           ",pd.amount_with_fee"
+           ",denoms.fee_deposit"
            ",pd.purse_pub"
            ",kc.age_commitment_hash"
            ",pd.coin_sig"
@@ -802,10 +796,8 @@ TEH_PG_get_coin_transactions (
            ",ref.merchant_sig"
            ",dep.h_contract_terms"
            ",ref.rtransaction_id"
-           ",ref.amount_with_fee_val"
-           ",ref.amount_with_fee_frac"
-           ",denom.fee_refund_val "
-           ",denom.fee_refund_frac "
+           ",ref.amount_with_fee"
+           ",denom.fee_refund"
            ",ref.refund_serial_id"
            " FROM refunds ref"
            " JOIN deposits dep"
@@ -819,10 +811,8 @@ TEH_PG_get_coin_transactions (
            "get_purse_decision_by_coin_pub",
            "SELECT"
            " pdes.purse_pub"
-           ",pd.amount_with_fee_val"
-           ",pd.amount_with_fee_frac"
-           ",denom.fee_refund_val "
-           ",denom.fee_refund_frac "
+           ",pd.amount_with_fee"
+           ",denom.fee_refund"
            ",pdes.purse_decision_serial_id"
            " FROM purse_deposits pd"
            " JOIN purse_decision pdes"
@@ -839,8 +829,7 @@ TEH_PG_get_coin_transactions (
            " coins.coin_pub"
            ",coin_sig"
            ",coin_blind"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            ",recoup_timestamp"
            ",denoms.denom_pub_hash"
            ",coins.denom_sig"
@@ -863,8 +852,7 @@ TEH_PG_get_coin_transactions (
            ",denoms.denom_pub_hash"
            ",coin_sig"
            ",coin_blind"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            ",recoup_timestamp"
            ",recoup_uuid"
            " FROM recoup rcp"
@@ -889,8 +877,7 @@ TEH_PG_get_coin_transactions (
            " old_coins.coin_pub AS old_coin_pub"
            ",coin_sig"
            ",coin_blind"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            ",recoup_timestamp"
            ",denoms.denom_pub_hash"
            ",coins.denom_sig"
@@ -913,8 +900,7 @@ TEH_PG_get_coin_transactions (
            " reserve_open_deposit_uuid"
            ",coin_sig"
            ",reserve_sig"
-           ",contribution_val"
-           ",contribution_frac"
+           ",contribution"
            " FROM reserves_open_deposits"
            " WHERE coin_pub=$1;");
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/exchangedb/pg_get_denomination_info.c 
b/src/exchangedb/pg_get_denomination_info.c
index 97250b62..4bae2979 100644
--- a/src/exchangedb/pg_get_denomination_info.c
+++ b/src/exchangedb/pg_get_denomination_info.c
@@ -64,8 +64,6 @@ TEH_PG_get_denomination_info (
     GNUNET_PQ_result_spec_end
   };
 
-
-    /* Used in #postgres_get_denomination_info() */
   PREPARE (pg,
            "denomination_get",
            "SELECT"
@@ -74,19 +72,14 @@ TEH_PG_get_denomination_info (
            ",expire_withdraw"
            ",expire_deposit"
            ",expire_legal"
-           ",coin_val"                                                /* value 
of this denom */
-           ",coin_frac"                                                /* 
fractional value of this denom */
-           ",fee_withdraw_val"
-           ",fee_withdraw_frac"
-           ",fee_deposit_val"
-           ",fee_deposit_frac"
-           ",fee_refresh_val"
-           ",fee_refresh_frac"
-           ",fee_refund_val"
-           ",fee_refund_frac"
+           ",coin"  /* value of this denom */
+           ",fee_withdraw"
+           ",fee_deposit"
+           ",fee_refresh"
+           ",fee_refund"
            ",age_mask"
            " FROM denominations"
-           " WHERE denom_pub_hash=$1;"); 
+           " WHERE denom_pub_hash=$1;");
   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
                                                  "denomination_get",
                                                  params,
@@ -96,4 +89,3 @@ TEH_PG_get_denomination_info (
   issue->denom_hash = *denom_pub_hash;
   return qs;
 }
-
diff --git a/src/exchangedb/pg_get_drain_profit.c 
b/src/exchangedb/pg_get_drain_profit.c
index d02802e1..75fccefc 100644
--- a/src/exchangedb/pg_get_drain_profit.c
+++ b/src/exchangedb/pg_get_drain_profit.c
@@ -58,7 +58,6 @@ TEH_PG_get_drain_profit (
     GNUNET_PQ_result_spec_end
   };
 
-
   PREPARE (pg,
            "get_profit_drain",
            "SELECT"
@@ -66,8 +65,7 @@ TEH_PG_get_drain_profit (
            ",account_section"
            ",payto_uri"
            ",trigger_date"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            ",master_sig"
            " FROM profit_drains"
            " WHERE wtid=$1;");
diff --git a/src/exchangedb/pg_get_global_fee.c 
b/src/exchangedb/pg_get_global_fee.c
index 990113fe..46addfa1 100644
--- a/src/exchangedb/pg_get_global_fee.c
+++ b/src/exchangedb/pg_get_global_fee.c
@@ -64,19 +64,14 @@ TEH_PG_get_global_fee (void *cls,
     GNUNET_PQ_result_spec_end
   };
 
-
-  /* Used in #postgres_get_global_fee() */
   PREPARE (pg,
            "get_global_fee",
            "SELECT "
            " start_date"
            ",end_date"
-           ",history_fee_val"
-           ",history_fee_frac"
-           ",account_fee_val"
-           ",account_fee_frac"
-           ",purse_fee_val"
-           ",purse_fee_frac"
+           ",history_fee"
+           ",account_fee"
+           ",purse_fee"
            ",purse_timeout"
            ",history_expiration"
            ",purse_account_limit"
diff --git a/src/exchangedb/pg_get_global_fees.c 
b/src/exchangedb/pg_get_global_fees.c
index e01eb2da..21be3598 100644
--- a/src/exchangedb/pg_get_global_fees.c
+++ b/src/exchangedb/pg_get_global_fees.c
@@ -143,25 +143,20 @@ TEH_PG_get_global_fees (void *cls,
     .status = GNUNET_OK
   };
 
-  /* Used in #postgres_get_global_fees() */
   PREPARE (pg,
            "get_global_fees",
            "SELECT "
            " start_date"
            ",end_date"
-           ",history_fee_val"
-           ",history_fee_frac"
-           ",account_fee_val"
-           ",account_fee_frac"
-           ",purse_fee_val"
-           ",purse_fee_frac"
+           ",history_fee"
+           ",account_fee"
+           ",purse_fee"
            ",purse_timeout"
            ",history_expiration"
            ",purse_account_limit"
            ",master_sig"
            " FROM global_fee"
            " WHERE start_date >= $1");
-
   return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
                                                "get_global_fees",
                                                params,
diff --git a/src/exchangedb/pg_get_melt.c b/src/exchangedb/pg_get_melt.c
index 8e5685ec..2221054b 100644
--- a/src/exchangedb/pg_get_melt.c
+++ b/src/exchangedb/pg_get_melt.c
@@ -72,13 +72,11 @@ TEH_PG_get_melt (void *cls,
            "get_melt",
            /* "SELECT"
               " denoms.denom_pub_hash"
-              ",denoms.fee_refresh_val"
-              ",denoms.fee_refresh_frac"
+              ",denoms.fee_refresh"
               ",old_coin_pub"
               ",old_coin_sig"
               ",kc.age_commitment_hash"
-              ",amount_with_fee_val"
-              ",amount_with_fee_frac"
+              ",amount_with_fee"
               ",noreveal_index"
               ",melt_serial_id"
               " FROM refresh_commitments"
@@ -94,13 +92,11 @@ TEH_PG_get_melt (void *cls,
            ")"
            "SELECT"
            " denoms.denom_pub_hash"
-           ",denoms.fee_refresh_val"
-           ",denoms.fee_refresh_frac"
+           ",denoms.fee_refresh"
            ",rc.old_coin_pub"
            ",rc.old_coin_sig"
            ",kc.age_commitment_hash"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
+           ",amount_with_fee"
            ",noreveal_index"
            ",melt_serial_id "
            "FROM ("
diff --git a/src/exchangedb/pg_get_purse_deposit.c 
b/src/exchangedb/pg_get_purse_deposit.c
index 8a135818..c09d7578 100644
--- a/src/exchangedb/pg_get_purse_deposit.c
+++ b/src/exchangedb/pg_get_purse_deposit.c
@@ -66,8 +66,7 @@ TEH_PG_get_purse_deposit (
            "select_purse_deposit_by_coin_pub",
            "SELECT "
            " coin_sig"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
+           ",amount_with_fee"
            ",denom_pub_hash"
            ",age_commitment_hash"
            ",partner_base_url"
diff --git a/src/exchangedb/pg_get_purse_request.c 
b/src/exchangedb/pg_get_purse_request.c
index c5f5aac7..9d2ee565 100644
--- a/src/exchangedb/pg_get_purse_request.c
+++ b/src/exchangedb/pg_get_purse_request.c
@@ -67,14 +67,11 @@ TEH_PG_get_purse_request (
            ",purse_expiration"
            ",h_contract_terms"
            ",age_limit"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
-           ",balance_val"
-           ",balance_frac"
+           ",amount_with_fee"
+           ",balance"
            ",purse_sig"
            " FROM purse_requests"
            " WHERE purse_pub=$1;");
-
   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
                                                    "get_purse_request",
                                                    params,
diff --git a/src/exchangedb/pg_get_reserve_history.c 
b/src/exchangedb/pg_get_reserve_history.c
index 6c12abc6..86a33946 100644
--- a/src/exchangedb/pg_get_reserve_history.c
+++ b/src/exchangedb/pg_get_reserve_history.c
@@ -653,8 +653,7 @@ TEH_PG_get_reserve_history (void *cls,
            /*
            "SELECT"
            " wire_reference"
-           ",credit_val"
-           ",credit_frac"
+           ",credit"
            ",execution_date"
            ",payto_uri AS sender_account_details"
            " FROM reserves_in"
@@ -667,14 +666,13 @@ TEH_PG_get_reserve_history (void *cls,
            "  FROM reserves_in "
            "  WHERE reserve_pub = $1 "
            ") "
-           "SELECT  "
-           "  wire_reference "
-           "  ,credit_val "
-           "  ,credit_frac "
-           "  ,execution_date "
-           "  ,payto_uri AS sender_account_details "
-           "FROM wire_targets "
-           "JOIN ri  "
+           "SELECT"
+           "  wire_reference"
+           "  ,credit"
+           "  ,execution_date"
+           "  ,payto_uri AS sender_account_details"
+           " FROM wire_targets"
+           " JOIN ri"
            "  ON (wire_target_h_payto = wire_source_h_payto) "
            "WHERE wire_target_h_payto = ( "
            "  SELECT wire_source_h_payto FROM ri "
@@ -688,10 +686,8 @@ TEH_PG_get_reserve_history (void *cls,
            ",ro.denom_sig"
            ",ro.reserve_sig"
            ",ro.execution_date"
-           ",ro.amount_with_fee_val"
-           ",ro.amount_with_fee_frac"
-           ",denom.fee_withdraw_val"
-           ",denom.fee_withdraw_frac"
+           ",ro.amount_with_fee"
+           ",denom.fee_withdraw"
            " FROM reserves res"
            " JOIN reserves_out_by_reserve ror"
            "   ON (res.reserve_uuid = ror.reserve_uuid)"
@@ -709,21 +705,19 @@ TEH_PG_get_reserve_history (void *cls,
            "    FROM reserves "
            "    WHERE reserve_pub = $1 "
            "  ) "
-           ") SELECT "
-           "  ro.h_blind_ev "
-           "  ,denom.denom_pub_hash "
-           "  ,ro.denom_sig "
-           "  ,ro.reserve_sig "
-           "  ,ro.execution_date "
-           "  ,ro.amount_with_fee_val "
-           "  ,ro.amount_with_fee_frac "
-           "  ,denom.fee_withdraw_val "
-           "  ,denom.fee_withdraw_frac "
-           "FROM robr "
-           "JOIN reserves_out ro "
-           "  ON (ro.h_blind_ev = robr.h_blind_ev) "
-           "JOIN denominations denom "
-           "  ON (ro.denominations_serial = denom.denominations_serial);");
+           ") SELECT"
+           "  ro.h_blind_ev"
+           "  ,denom.denom_pub_hash"
+           "  ,ro.denom_sig"
+           "  ,ro.reserve_sig"
+           "  ,ro.execution_date"
+           "  ,ro.amount_with_fee"
+           "  ,denom.fee_withdraw"
+           " FROM robr"
+           " JOIN reserves_out ro"
+           "   ON (ro.h_blind_ev = robr.h_blind_ev)"
+           " JOIN denominations denom"
+           "   ON (ro.denominations_serial = denom.denominations_serial);");
   PREPARE (pg,
            "recoup_by_reserve",
            /*
@@ -731,8 +725,7 @@ TEH_PG_get_reserve_history (void *cls,
            " recoup.coin_pub"
            ",recoup.coin_sig"
            ",recoup.coin_blind"
-           ",recoup.amount_val"
-           ",recoup.amount_frac"
+           ",recoup.amount"
            ",recoup.recoup_timestamp"
            ",denominations.denom_pub_hash"
            ",known_coins.denom_sig"
@@ -753,10 +746,9 @@ TEH_PG_get_reserve_history (void *cls,
            "     WHERE reserves.reserve_pub=$1);",
            */
            "SELECT robr.coin_pub "
-           "  ,robr.coin_sig "
-           "  ,robr.coin_blind "
-           "  ,robr.amount_val "
-           "  ,robr.amount_frac "
+           "  ,robr.coin_sig"
+           "  ,robr.coin_blind"
+           "  ,robr.amount"
            "  ,robr.recoup_timestamp "
            "  ,denominations.denom_pub_hash "
            "  ,robr.denom_sig "
@@ -766,10 +758,8 @@ TEH_PG_get_reserve_history (void *cls,
   PREPARE (pg,
            "close_by_reserve",
            "SELECT"
-           " amount_val"
-           ",amount_frac"
-           ",closing_fee_val"
-           ",closing_fee_frac"
+           " amount"
+           ",closing_fee"
            ",execution_date"
            ",payto_uri AS receiver_account"
            ",wtid"
@@ -780,12 +770,9 @@ TEH_PG_get_reserve_history (void *cls,
   PREPARE (pg,
            "merge_by_reserve",
            "SELECT"
-           " pr.amount_with_fee_val"
-           ",pr.amount_with_fee_frac"
-           ",pr.balance_val"
-           ",pr.balance_frac"
-           ",pr.purse_fee_val"
-           ",pr.purse_fee_frac"
+           " pr.amount_with_fee"
+           ",pr.balance"
+           ",pr.purse_fee"
            ",pr.h_contract_terms"
            ",pr.merge_pub"
            ",am.reserve_sig"
@@ -808,8 +795,7 @@ TEH_PG_get_reserve_history (void *cls,
   PREPARE (pg,
            "history_by_reserve",
            "SELECT"
-           " history_fee_val"
-           ",history_fee_frac"
+           " history_fee"
            ",request_timestamp"
            ",reserve_sig"
            " FROM history_requests"
@@ -817,8 +803,7 @@ TEH_PG_get_reserve_history (void *cls,
   PREPARE (pg,
            "open_request_by_reserve",
            "SELECT"
-           " reserve_payment_val"
-           ",reserve_payment_frac"
+           " reserve_payment"
            ",request_timestamp"
            ",expiration_date"
            ",requested_purse_limit"
@@ -944,8 +929,7 @@ TEH_PG_get_reserve_status (void *cls,
            /*
            "SELECT"
            " wire_reference"
-           ",credit_val"
-           ",credit_frac"
+           ",credit"
            ",execution_date"
            ",payto_uri AS sender_account_details"
            " FROM reserves_in"
@@ -960,15 +944,14 @@ TEH_PG_get_reserve_status (void *cls,
            "  WHERE reserve_pub = $1 "
            ") "
            "SELECT  "
-           "  wire_reference "
-           "  ,credit_val "
-           "  ,credit_frac "
-           "  ,execution_date "
-           "  ,payto_uri AS sender_account_details "
-           "FROM wire_targets "
-           "JOIN ri  "
-           "  ON (wire_target_h_payto = wire_source_h_payto) "
-           "WHERE execution_date >= $2"
+           "  wire_reference"
+           "  ,credit"
+           "  ,execution_date"
+           "  ,payto_uri AS sender_account_details"
+           " FROM wire_targets"
+           " JOIN ri"
+           "  ON (wire_target_h_payto = wire_source_h_payto)"
+           " WHERE execution_date >= $2"
            "  AND wire_target_h_payto = ( "
            "  SELECT wire_source_h_payto FROM ri "
            "); ");
@@ -981,10 +964,8 @@ TEH_PG_get_reserve_status (void *cls,
            ",ro.denom_sig"
            ",ro.reserve_sig"
            ",ro.execution_date"
-           ",ro.amount_with_fee_val"
-           ",ro.amount_with_fee_frac"
-           ",denom.fee_withdraw_val"
-           ",denom.fee_withdraw_frac"
+           ",ro.amount_with_fee"
+           ",denom.fee_withdraw"
            " FROM reserves res"
            " JOIN reserves_out_by_reserve ror"
            "   ON (res.reserve_uuid = ror.reserve_uuid)"
@@ -1004,20 +985,18 @@ TEH_PG_get_reserve_status (void *cls,
            "    WHERE reserve_pub = $1 "
            "  ) "
            ") SELECT "
-           "  ro.h_blind_ev "
-           "  ,denom.denom_pub_hash "
-           "  ,ro.denom_sig "
-           "  ,ro.reserve_sig "
-           "  ,ro.execution_date "
-           "  ,ro.amount_with_fee_val "
-           "  ,ro.amount_with_fee_frac "
-           "  ,denom.fee_withdraw_val "
-           "  ,denom.fee_withdraw_frac "
-           "FROM robr "
-           "JOIN reserves_out ro "
-           "  ON (ro.h_blind_ev = robr.h_blind_ev) "
-           "JOIN denominations denom "
-           "  ON (ro.denominations_serial = denom.denominations_serial)"
+           "  ro.h_blind_ev"
+           "  ,denom.denom_pub_hash"
+           "  ,ro.denom_sig"
+           "  ,ro.reserve_sig"
+           "  ,ro.execution_date"
+           "  ,ro.amount_with_fee"
+           "  ,denom.fee_withdraw"
+           " FROM robr"
+           " JOIN reserves_out ro"
+           "   ON (ro.h_blind_ev = robr.h_blind_ev)"
+           " JOIN denominations denom"
+           "   ON (ro.denominations_serial = denom.denominations_serial)"
            " WHERE ro.execution_date>=$2;");
   PREPARE (pg,
            "recoup_by_reserve_truncated",
@@ -1026,8 +1005,7 @@ TEH_PG_get_reserve_status (void *cls,
            " recoup.coin_pub"
            ",recoup.coin_sig"
            ",recoup.coin_blind"
-           ",recoup.amount_val"
-           ",recoup.amount_frac"
+           ",recoup.amount"
            ",recoup.recoup_timestamp"
            ",denominations.denom_pub_hash"
            ",known_coins.denom_sig"
@@ -1051,8 +1029,7 @@ TEH_PG_get_reserve_status (void *cls,
            "SELECT robr.coin_pub "
            "  ,robr.coin_sig "
            "  ,robr.coin_blind "
-           "  ,robr.amount_val "
-           "  ,robr.amount_frac "
+           "  ,robr.amount"
            "  ,robr.recoup_timestamp "
            "  ,denominations.denom_pub_hash "
            "  ,robr.denom_sig "
@@ -1063,10 +1040,8 @@ TEH_PG_get_reserve_status (void *cls,
   PREPARE (pg,
            "close_by_reserve_truncated",
            "SELECT"
-           " amount_val"
-           ",amount_frac"
-           ",closing_fee_val"
-           ",closing_fee_frac"
+           " amount"
+           ",closing_fee"
            ",execution_date"
            ",payto_uri AS receiver_account"
            ",wtid"
@@ -1078,12 +1053,9 @@ TEH_PG_get_reserve_status (void *cls,
   PREPARE (pg,
            "merge_by_reserve_truncated",
            "SELECT"
-           " pr.amount_with_fee_val"
-           ",pr.amount_with_fee_frac"
-           ",pr.balance_val"
-           ",pr.balance_frac"
-           ",pr.purse_fee_val"
-           ",pr.purse_fee_frac"
+           " pr.amount_with_fee"
+           ",pr.balance"
+           ",pr.purse_fee"
            ",pr.h_contract_terms"
            ",pr.merge_pub"
            ",am.reserve_sig"
@@ -1107,8 +1079,7 @@ TEH_PG_get_reserve_status (void *cls,
   PREPARE (pg,
            "history_by_reserve_truncated",
            "SELECT"
-           " history_fee_val"
-           ",history_fee_frac"
+           " history_fee"
            ",request_timestamp"
            ",reserve_sig"
            " FROM history_requests"
@@ -1117,8 +1088,7 @@ TEH_PG_get_reserve_status (void *cls,
   PREPARE (pg,
            "open_request_by_reserve_truncated",
            "SELECT"
-           " reserve_payment_val"
-           ",reserve_payment_frac"
+           " reserve_payment"
            ",request_timestamp"
            ",expiration_date"
            ",requested_purse_limit"
diff --git a/src/exchangedb/pg_get_unfinished_close_requests.c 
b/src/exchangedb/pg_get_unfinished_close_requests.c
index fa8abdf8..990e8e00 100644
--- a/src/exchangedb/pg_get_unfinished_close_requests.c
+++ b/src/exchangedb/pg_get_unfinished_close_requests.c
@@ -142,8 +142,7 @@ TEH_PG_get_unfinished_close_requests (
            "    reserve_pub"
            "   ,close_request_serial_id"
            "   ,close_timestamp AS expiration_date"
-           "   ,close_val"
-           "   ,close_frac"
+           "   ,close"
            "   ,(SELECT payto_uri"
            "       FROM reserves_in ri"
            "       JOIN wire_targets wt ON (ri.wire_source_h_payto = 
wt.wire_target_h_payto)"
diff --git a/src/exchangedb/pg_get_wire_fee.c b/src/exchangedb/pg_get_wire_fee.c
index 4aab68b8..40f517f2 100644
--- a/src/exchangedb/pg_get_wire_fee.c
+++ b/src/exchangedb/pg_get_wire_fee.c
@@ -54,17 +54,13 @@ TEH_PG_get_wire_fee (void *cls,
     GNUNET_PQ_result_spec_end
   };
 
-
-  /* Used in #postgres_get_wire_fee() */
   PREPARE (pg,
            "get_wire_fee",
            "SELECT "
            " start_date"
            ",end_date"
-           ",wire_fee_val"
-           ",wire_fee_frac"
-           ",closing_fee_val"
-           ",closing_fee_frac"
+           ",wire_fee"
+           ",closing_fee"
            ",master_sig"
            " FROM wire_fee"
            " WHERE wire_method=$1"
diff --git a/src/exchangedb/pg_get_wire_fees.c 
b/src/exchangedb/pg_get_wire_fees.c
index e34d44a9..193ccff6 100644
--- a/src/exchangedb/pg_get_wire_fees.c
+++ b/src/exchangedb/pg_get_wire_fees.c
@@ -126,14 +126,11 @@ TEH_PG_get_wire_fees (void *cls,
   };
   enum GNUNET_DB_QueryStatus qs;
 
-
   PREPARE (pg,
            "get_wire_fees",
            "SELECT"
-           " wire_fee_val"
-           ",wire_fee_frac"
-           ",closing_fee_val"
-           ",closing_fee_frac"
+           " wire_fee"
+           ",closing_fee"
            ",start_date"
            ",end_date"
            ",master_sig"
diff --git a/src/exchangedb/pg_get_withdraw_info.c 
b/src/exchangedb/pg_get_withdraw_info.c
index d6a180b0..e06fa376 100644
--- a/src/exchangedb/pg_get_withdraw_info.c
+++ b/src/exchangedb/pg_get_withdraw_info.c
@@ -55,10 +55,6 @@ TEH_PG_get_withdraw_info (
     GNUNET_PQ_result_spec_end
   };
 
-  /* Used in #postgres_get_withdraw_info() to
-      locate the response for a /reserve/withdraw request
-      using the hash of the blinded message.  Used to
-      make sure /reserve/withdraw requests are idempotent. */
   PREPARE (pg,
            "get_withdraw_info",
            "SELECT"
@@ -68,10 +64,8 @@ TEH_PG_get_withdraw_info (
            ",reserves.reserve_pub"
            ",execution_date"
            ",h_blind_ev"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
-           ",denom.fee_withdraw_val"
-           ",denom.fee_withdraw_frac"
+           ",amount_with_fee"
+           ",denom.fee_withdraw"
            " FROM reserves_out"
            "    JOIN reserves"
            "      USING (reserve_uuid)"
diff --git a/src/exchangedb/pg_have_deposit2.c 
b/src/exchangedb/pg_have_deposit2.c
index 92c30060..ccb4f5c9 100644
--- a/src/exchangedb/pg_have_deposit2.c
+++ b/src/exchangedb/pg_have_deposit2.c
@@ -70,16 +70,11 @@ TEH_PG_have_deposit2 (
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Getting deposits for coin %s\n",
               TALER_B2S (coin_pub));
-
-  /* Fetch an existing deposit request, used to ensure idempotency
-     during /deposit processing. Used in #postgres_have_deposit(). */
   PREPARE (pg,
            "get_deposit",
            "SELECT"
-           " dep.amount_with_fee_val"
-           ",dep.amount_with_fee_frac"
-           ",denominations.fee_deposit_val"
-           ",denominations.fee_deposit_frac"
+           " dep.amount_with_fee"
+           ",denominations.fee_deposit"
            ",dep.wallet_timestamp"
            ",dep.exchange_timestamp"
            ",dep.refund_deadline"
diff --git a/src/exchangedb/pg_helper.h b/src/exchangedb/pg_helper.h
index 512f7505..56f4afc3 100644
--- a/src/exchangedb/pg_helper.h
+++ b/src/exchangedb/pg_helper.h
@@ -141,19 +141,8 @@ struct PostgresClosure
  * @param field name of the database field to fetch amount from
  * @param[out] amountp pointer to amount to set
  */
-#define TALER_PQ_RESULT_SPEC_AMOUNT(field,amountp) TALER_PQ_result_spec_amount 
( \
-    field,pg->currency,amountp)
-
-
-/**
- * Wrapper macro to add the currency from the plugin's state
- * when fetching amounts from the database.  NBO variant.
- *
- * @param field name of the database field to fetch amount from
- * @param[out] amountp pointer to amount to set
- */
-#define TALER_PQ_RESULT_SPEC_AMOUNT_NBO(field,                          \
-                                        amountp) 
TALER_PQ_result_spec_amount_nbo ( \
+#define TALER_PQ_RESULT_SPEC_AMOUNT(field, \
+                                    amountp) TALER_PQ_result_spec_amount_tuple 
( \
     field,pg->currency,amountp)
 
 
diff --git a/src/exchangedb/pg_insert_aml_decision.c 
b/src/exchangedb/pg_insert_aml_decision.c
index fcf67ee4..80eb7f2b 100644
--- a/src/exchangedb/pg_insert_aml_decision.c
+++ b/src/exchangedb/pg_insert_aml_decision.c
@@ -55,7 +55,8 @@ TEH_PG_insert_aml_decision (
     : NULL;
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_auto_from_type (h_payto),
-    TALER_PQ_query_param_amount (new_threshold),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       new_threshold),
     GNUNET_PQ_query_param_uint32 (&ns),
     GNUNET_PQ_query_param_timestamp (&decision_time),
     GNUNET_PQ_query_param_string (justification),
@@ -83,7 +84,7 @@ TEH_PG_insert_aml_decision (
            " out_invalid_officer"
            ",out_last_date"
            " FROM exchange_do_insert_aml_decision"
-           "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);");
+           "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);");
   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
                                                  "do_insert_aml_decision",
                                                  params,
diff --git a/src/exchangedb/pg_insert_close_request.c 
b/src/exchangedb/pg_insert_close_request.c
index 387dafd9..01160b74 100644
--- a/src/exchangedb/pg_insert_close_request.c
+++ b/src/exchangedb/pg_insert_close_request.c
@@ -41,8 +41,10 @@ TEH_PG_insert_close_request (
     GNUNET_PQ_query_param_auto_from_type (reserve_pub),
     GNUNET_PQ_query_param_timestamp (&request_timestamp),
     GNUNET_PQ_query_param_auto_from_type (reserve_sig),
-    TALER_PQ_query_param_amount (balance),
-    TALER_PQ_query_param_amount (closing_fee),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       balance),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       closing_fee),
     GNUNET_PQ_query_param_string (payto_uri),
     GNUNET_PQ_query_param_end
   };
@@ -53,14 +55,12 @@ TEH_PG_insert_close_request (
            "(reserve_pub"
            ",close_timestamp"
            ",reserve_sig"
-           ",close_val"
-           ",close_frac"
-           ",close_fee_val"
-           ",close_fee_frac"
+           ",close"
+           ",close_fee"
            ",payto_uri"
            ")"
            "VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8)"
+           "($1, $2, $3, $4, $5, $6)"
            " ON CONFLICT DO NOTHING;");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_account_close",
diff --git a/src/exchangedb/pg_insert_denomination_info.c 
b/src/exchangedb/pg_insert_denomination_info.c
index 30199611..620d6dd7 100644
--- a/src/exchangedb/pg_insert_denomination_info.c
+++ b/src/exchangedb/pg_insert_denomination_info.c
@@ -42,11 +42,16 @@ TEH_PG_insert_denomination_info (
     GNUNET_PQ_query_param_timestamp (&issue->expire_withdraw),
     GNUNET_PQ_query_param_timestamp (&issue->expire_deposit),
     GNUNET_PQ_query_param_timestamp (&issue->expire_legal),
-    TALER_PQ_query_param_amount (&issue->value),
-    TALER_PQ_query_param_amount (&issue->fees.withdraw),
-    TALER_PQ_query_param_amount (&issue->fees.deposit),
-    TALER_PQ_query_param_amount (&issue->fees.refresh),
-    TALER_PQ_query_param_amount (&issue->fees.refund),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &issue->value),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &issue->fees.withdraw),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &issue->fees.deposit),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &issue->fees.refresh),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &issue->fees.refund),
     GNUNET_PQ_query_param_uint32 (&denom_pub->age_mask.bits),
     GNUNET_PQ_query_param_end
   };
@@ -81,20 +86,15 @@ TEH_PG_insert_denomination_info (
            ",expire_withdraw"
            ",expire_deposit"
            ",expire_legal"
-           ",coin_val"                                                /* value 
of this denom */
-           ",coin_frac"                                                /* 
fractional value of this denom */
-           ",fee_withdraw_val"
-           ",fee_withdraw_frac"
-           ",fee_deposit_val"
-           ",fee_deposit_frac"
-           ",fee_refresh_val"
-           ",fee_refresh_frac"
-           ",fee_refund_val"
-           ",fee_refund_frac"
+           ",coin"  /* value of this denom */
+           ",fee_withdraw"
+           ",fee_deposit"
+           ",fee_refresh"
+           ",fee_refund"
            ",age_mask"
            ") VALUES "
            "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
-           " $11, $12, $13, $14, $15, $16, $17, $18);");
+           " $11, $12, $13);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "denomination_insert",
                                              params);
diff --git a/src/exchangedb/pg_insert_deposit.c 
b/src/exchangedb/pg_insert_deposit.c
index a4d68fe1..d674983e 100644
--- a/src/exchangedb/pg_insert_deposit.c
+++ b/src/exchangedb/pg_insert_deposit.c
@@ -52,7 +52,8 @@ TEH_PG_insert_deposit (void *cls,
     uint64_t shard = TEH_PG_compute_shard (&deposit->merchant_pub);
     struct GNUNET_PQ_QueryParam params[] = {
       GNUNET_PQ_query_param_auto_from_type (&deposit->coin.coin_pub),
-      TALER_PQ_query_param_amount (&deposit->amount_with_fee),
+      TALER_PQ_query_param_amount_tuple (pg->conn,
+                                         &deposit->amount_with_fee),
       GNUNET_PQ_query_param_timestamp (&deposit->timestamp),
       GNUNET_PQ_query_param_timestamp (&deposit->refund_deadline),
       GNUNET_PQ_query_param_timestamp (&deposit->wire_deadline),
@@ -73,15 +74,13 @@ TEH_PG_insert_deposit (void *cls,
       GNUNET_TIME_timestamp2s (deposit->wire_deadline),
       (unsigned long long) deposit->wire_deadline.abs_time.abs_value_us,
       (unsigned long long) deposit->refund_deadline.abs_time.abs_value_us);
-    /* Store information about a /deposit the exchange is to execute.
-       Used in #postgres_insert_deposit().  Only used in test cases. */
+
     PREPARE (pg,
              "insert_deposit",
              "INSERT INTO deposits "
              "(known_coin_id"
              ",coin_pub"
-             ",amount_with_fee_val"
-             ",amount_with_fee_frac"
+             ",amount_with_fee"
              ",wallet_timestamp"
              ",refund_deadline"
              ",wire_deadline"
@@ -93,7 +92,7 @@ TEH_PG_insert_deposit (void *cls,
              ",exchange_timestamp"
              ",shard"
              ") SELECT known_coin_id, $1, $2, $3, $4, $5, $6, "
-             " $7, $8, $9, $10, $11, $12, $13"
+             " $7, $8, $9, $10, $11, $12"
              "    FROM known_coins"
              "   WHERE coin_pub=$1"
              " ON CONFLICT DO NOTHING;");
diff --git a/src/exchangedb/pg_insert_drain_profit.c 
b/src/exchangedb/pg_insert_drain_profit.c
index 34ab0332..26dcb9d0 100644
--- a/src/exchangedb/pg_insert_drain_profit.c
+++ b/src/exchangedb/pg_insert_drain_profit.c
@@ -41,11 +41,12 @@ TEH_PG_insert_drain_profit (
     GNUNET_PQ_query_param_string (account_section),
     GNUNET_PQ_query_param_string (payto_uri),
     GNUNET_PQ_query_param_timestamp (&request_timestamp),
-    TALER_PQ_query_param_amount (amount),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       amount),
     GNUNET_PQ_query_param_auto_from_type (master_sig),
     GNUNET_PQ_query_param_end
   };
-  /* Used in #postgres_insert_drain_profit() */
+
   PREPARE (pg,
            "drain_profit_insert",
            "INSERT INTO profit_drains "
@@ -53,11 +54,9 @@ TEH_PG_insert_drain_profit (
            ",account_section"
            ",payto_uri"
            ",trigger_date"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            ",master_sig"
-           ") VALUES ($1, $2, $3, $4, $5, $6, $7);");
-
+           ") VALUES ($1, $2, $3, $4, $5, $6);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "drain_profit_insert",
                                              params);
diff --git a/src/exchangedb/pg_insert_global_fee.c 
b/src/exchangedb/pg_insert_global_fee.c
index 1c34016a..0b540649 100644
--- a/src/exchangedb/pg_insert_global_fee.c
+++ b/src/exchangedb/pg_insert_global_fee.c
@@ -40,9 +40,12 @@ TEH_PG_insert_global_fee (void *cls,
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_timestamp (&start_date),
     GNUNET_PQ_query_param_timestamp (&end_date),
-    TALER_PQ_query_param_amount (&fees->history),
-    TALER_PQ_query_param_amount (&fees->account),
-    TALER_PQ_query_param_amount (&fees->purse),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &fees->history),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &fees->account),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &fees->purse),
     GNUNET_PQ_query_param_relative_time (&purse_timeout),
     GNUNET_PQ_query_param_relative_time (&history_expiration),
     GNUNET_PQ_query_param_uint32 (&purse_account_limit),
@@ -119,18 +122,15 @@ TEH_PG_insert_global_fee (void *cls,
            "INSERT INTO global_fee "
            "(start_date"
            ",end_date"
-           ",history_fee_val"
-           ",history_fee_frac"
-           ",account_fee_val"
-           ",account_fee_frac"
-           ",purse_fee_val"
-           ",purse_fee_frac"
+           ",history_fee"
+           ",account_fee"
+           ",purse_fee"
            ",purse_timeout"
            ",history_expiration"
            ",purse_account_limit"
            ",master_sig"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);");
+           "($1, $2, $3, $4, $5, $6, $7, $8, $9);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_global_fee",
                                              params);
diff --git a/src/exchangedb/pg_insert_partner.c 
b/src/exchangedb/pg_insert_partner.c
index 5abb2c91..24c06005 100644
--- a/src/exchangedb/pg_insert_partner.c
+++ b/src/exchangedb/pg_insert_partner.c
@@ -42,7 +42,8 @@ TEH_PG_insert_partner (void *cls,
     GNUNET_PQ_query_param_timestamp (&start_date),
     GNUNET_PQ_query_param_timestamp (&end_date),
     GNUNET_PQ_query_param_relative_time (&wad_frequency),
-    TALER_PQ_query_param_amount (wad_fee),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       wad_fee),
     GNUNET_PQ_query_param_auto_from_type (master_sig),
     GNUNET_PQ_query_param_string (partner_base_url),
     GNUNET_PQ_query_param_end
@@ -56,12 +57,11 @@ TEH_PG_insert_partner (void *cls,
            "  ,start_date"
            "  ,end_date"
            "  ,wad_frequency"
-           "  ,wad_fee_val"
-           "  ,wad_fee_frac"
+           "  ,wad_fee"
            "  ,master_sig"
            "  ,partner_base_url"
            "  ) VALUES "
-           "  ($1, $2, $3, $4, $5, $6, $7, $8)"
+           "  ($1, $2, $3, $4, $5, $6, $7)"
            "  ON CONFLICT DO NOTHING;");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_partner",
diff --git a/src/exchangedb/pg_insert_purse_request.c 
b/src/exchangedb/pg_insert_purse_request.c
index f42129ec..05977b7b 100644
--- a/src/exchangedb/pg_insert_purse_request.c
+++ b/src/exchangedb/pg_insert_purse_request.c
@@ -56,8 +56,10 @@ TEH_PG_insert_purse_request (
     GNUNET_PQ_query_param_uint32 (&age_limit),
     GNUNET_PQ_query_param_uint32 (&flags32),
     GNUNET_PQ_query_param_bool (in_reserve_quota),
-    TALER_PQ_query_param_amount (amount),
-    TALER_PQ_query_param_amount (purse_fee),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       amount),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       purse_fee),
     GNUNET_PQ_query_param_auto_from_type (purse_sig),
     GNUNET_PQ_query_param_end
   };
@@ -74,13 +76,11 @@ TEH_PG_insert_purse_request (
            "  ,age_limit"
            "  ,flags"
            "  ,in_reserve_quota"
-           "  ,amount_with_fee_val"
-           "  ,amount_with_fee_frac"
-           "  ,purse_fee_val"
-           "  ,purse_fee_frac"
+           "  ,amount_with_fee"
+           "  ,purse_fee"
            "  ,purse_sig"
            "  ) VALUES "
-           "  ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)"
+           "  ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)"
            "  ON CONFLICT DO NOTHING;");
   qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                            "insert_purse_request",
diff --git a/src/exchangedb/pg_insert_records_by_table.c 
b/src/exchangedb/pg_insert_records_by_table.c
index ebac7cee..97a7cdfb 100644
--- a/src/exchangedb/pg_insert_records_by_table.c
+++ b/src/exchangedb/pg_insert_records_by_table.c
@@ -74,14 +74,20 @@ irbt_cb_table_denominations (struct PostgresClosure *pg,
       &td->details.denominations.expire_deposit),
     GNUNET_PQ_query_param_timestamp (
       &td->details.denominations.expire_legal),
-    TALER_PQ_query_param_amount (&td->details.denominations.coin),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.denominations.coin),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.denominations.fees.withdraw),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.denominations.fees.deposit),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.denominations.fees.refresh),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.denominations.fees.refund),
     GNUNET_PQ_query_param_end
   };
@@ -99,19 +105,14 @@ irbt_cb_table_denominations (struct PostgresClosure *pg,
            ",expire_withdraw"
            ",expire_deposit"
            ",expire_legal"
-           ",coin_val"
-           ",coin_frac"
-           ",fee_withdraw_val"
-           ",fee_withdraw_frac"
-           ",fee_deposit_val"
-           ",fee_deposit_frac"
-           ",fee_refresh_val"
-           ",fee_refresh_frac"
-           ",fee_refund_val"
-           ",fee_refund_frac"
+           ",coin"
+           ",fee_withdraw"
+           ",fee_deposit"
+           ",fee_refresh"
+           ",fee_refund"
            ") VALUES "
            "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
-           " $11, $12, $13, $14, $15, $16, $17, $18, $19, $20);");
+           " $11, $12, $13, $14, $15);");
 
   TALER_denom_pub_hash (
     &td->details.denominations.denom_pub,
@@ -321,7 +322,9 @@ irbt_cb_table_reserves_in (struct PostgresClosure *pg,
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_uint64 (&td->serial),
     GNUNET_PQ_query_param_uint64 (&td->details.reserves_in.wire_reference),
-    TALER_PQ_query_param_amount (&td->details.reserves_in.credit),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.reserves_in.credit),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.reserves_in.sender_account_h_payto),
     GNUNET_PQ_query_param_string (
@@ -337,14 +340,13 @@ irbt_cb_table_reserves_in (struct PostgresClosure *pg,
            "INSERT INTO reserves_in"
            "(reserve_in_serial_id"
            ",wire_reference"
-           ",credit_val"
-           ",credit_frac"
+           ",credit"
            ",wire_source_h_payto"
            ",exchange_account_section"
            ",execution_date"
            ",reserve_pub"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8);");
+           "($1, $2, $3, $4, $5, $6, $7);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_into_table_reserves_in",
                                              params);
@@ -368,7 +370,8 @@ irbt_cb_table_reserves_open_requests (struct 
PostgresClosure *pg,
       &td->details.reserves_open_requests.expiration_date),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.reserves_open_requests.reserve_sig),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.reserves_open_requests.reserve_payment),
     GNUNET_PQ_query_param_uint32 (
       &td->details.reserves_open_requests.requested_purse_limit),
@@ -383,11 +386,10 @@ irbt_cb_table_reserves_open_requests (struct 
PostgresClosure *pg,
            ",request_timestamp"
            ",expiration_date"
            ",reserve_sig"
-           ",reserve_payment_val"
-           ",reserve_payment_frac"
+           ",reserve_payment"
            ",requested_purse_limit"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8);");
+           "($1, $2, $3, $4, $5, $6, $7);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              
"insert_into_table_reserves_open_requests",
                                              params);
@@ -413,7 +415,8 @@ irbt_cb_table_reserves_open_deposits (
       &td->details.reserves_open_deposits.coin_sig),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.reserves_open_deposits.reserve_sig),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.reserves_open_deposits.contribution),
     GNUNET_PQ_query_param_end
   };
@@ -426,10 +429,9 @@ irbt_cb_table_reserves_open_deposits (
            ",reserve_pub"
            ",coin_pub"
            ",coin_sig"
-           ",contribution_val"
-           ",contribution_frac"
+           ",contribution"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7);");
+           "($1, $2, $3, $4, $5, $6);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              
"insert_into_table_reserves_open_deposits",
                                              params);
@@ -454,8 +456,12 @@ irbt_cb_table_reserves_close (struct PostgresClosure *pg,
       &td->details.reserves_close.wtid),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.reserves_close.sender_account_h_payto),
-    TALER_PQ_query_param_amount (&td->details.reserves_close.amount),
-    TALER_PQ_query_param_amount (&td->details.reserves_close.closing_fee),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.reserves_close.amount),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.reserves_close.closing_fee),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.reserves_close.reserve_pub),
     GNUNET_PQ_query_param_end
@@ -468,13 +474,11 @@ irbt_cb_table_reserves_close (struct PostgresClosure *pg,
            ",execution_date"
            ",wtid"
            ",wire_target_h_payto"
-           ",amount_val"
-           ",amount_frac"
-           ",closing_fee_val"
-           ",closing_fee_frac"
+           ",amount"
+           ",closing_fee"
            ",reserve_pub"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8, $9);");
+           "($1, $2, $3, $4, $5, $6, $7);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              
"insert_into_table_reserves_close",
                                              params);
@@ -505,7 +509,8 @@ irbt_cb_table_reserves_out (struct PostgresClosure *pg,
       &td->details.reserves_out.reserve_sig),
     GNUNET_PQ_query_param_timestamp (
       &td->details.reserves_out.execution_date),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.reserves_out.amount_with_fee),
     GNUNET_PQ_query_param_end
   };
@@ -520,10 +525,9 @@ irbt_cb_table_reserves_out (struct PostgresClosure *pg,
            ",reserve_uuid"
            ",reserve_sig"
            ",execution_date"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
+           ",amount_with_fee"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8, $9);");
+           "($1, $2, $3, $4, $5, $6, $7, $8);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_into_table_reserves_out",
                                              params);
@@ -727,7 +731,8 @@ irbt_cb_table_refresh_commitments (struct PostgresClosure 
*pg,
     GNUNET_PQ_query_param_auto_from_type (&td->details.refresh_commitments.rc),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.refresh_commitments.old_coin_sig),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.refresh_commitments.amount_with_fee),
     GNUNET_PQ_query_param_uint32 (
       &td->details.refresh_commitments.noreveal_index),
@@ -742,12 +747,11 @@ irbt_cb_table_refresh_commitments (struct PostgresClosure 
*pg,
            "(melt_serial_id"
            ",rc"
            ",old_coin_sig"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
+           ",amount_with_fee"
            ",noreveal_index"
            ",old_coin_pub"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7);");
+           "($1, $2, $3, $4, $5, $6);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              
"insert_into_table_refresh_commitments",
                                              params);
@@ -866,7 +870,9 @@ irbt_cb_table_deposits (struct PostgresClosure *pg,
     GNUNET_PQ_query_param_uint64 (&td->details.deposits.known_coin_id),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.deposits.coin_pub),
-    TALER_PQ_query_param_amount (&td->details.deposits.amount_with_fee),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.deposits.amount_with_fee),
     GNUNET_PQ_query_param_timestamp (&td->details.deposits.wallet_timestamp),
     GNUNET_PQ_query_param_timestamp (
       &td->details.deposits.exchange_timestamp),
@@ -894,8 +900,7 @@ irbt_cb_table_deposits (struct PostgresClosure *pg,
            ",shard"
            ",known_coin_id"
            ",coin_pub"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
+           ",amount_with_fee"
            ",wallet_timestamp"
            ",exchange_timestamp"
            ",refund_deadline"
@@ -909,7 +914,7 @@ irbt_cb_table_deposits (struct PostgresClosure *pg,
            ",policy_details_serial_id"
            ") VALUES "
            "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
-           " $11, $12, $13, $14, $15, $16, $17);");
+           " $11, $12, $13, $14, $15, $16);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_into_table_deposits",
                                              params);
@@ -931,7 +936,9 @@ irbt_cb_table_refunds (struct PostgresClosure *pg,
     GNUNET_PQ_query_param_auto_from_type (&td->details.refunds.coin_pub),
     GNUNET_PQ_query_param_auto_from_type (&td->details.refunds.merchant_sig),
     GNUNET_PQ_query_param_uint64 (&td->details.refunds.rtransaction_id),
-    TALER_PQ_query_param_amount (&td->details.refunds.amount_with_fee),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.refunds.amount_with_fee),
     GNUNET_PQ_query_param_uint64 (&td->details.refunds.deposit_serial_id),
     GNUNET_PQ_query_param_end
   };
@@ -943,11 +950,10 @@ irbt_cb_table_refunds (struct PostgresClosure *pg,
            ",coin_pub"
            ",merchant_sig"
            ",rtransaction_id"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
+           ",amount_with_fee"
            ",deposit_serial_id"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7);");
+           "($1, $2, $3, $4, $5, $6);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_into_table_refunds",
                                              params);
@@ -972,7 +978,9 @@ irbt_cb_table_wire_out (struct PostgresClosure *pg,
       &td->details.wire_out.wire_target_h_payto),
     GNUNET_PQ_query_param_string (
       td->details.wire_out.exchange_account_section),
-    TALER_PQ_query_param_amount (&td->details.wire_out.amount),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.wire_out.amount),
     GNUNET_PQ_query_param_end
   };
 
@@ -984,10 +992,9 @@ irbt_cb_table_wire_out (struct PostgresClosure *pg,
            ",wtid_raw"
            ",wire_target_h_payto"
            ",exchange_account_section"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7);");
+           "($1, $2, $3, $4, $5, $6);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_into_table_wire_out",
                                              params);
@@ -1042,8 +1049,12 @@ irbt_cb_table_wire_fee (struct PostgresClosure *pg,
     GNUNET_PQ_query_param_string (td->details.wire_fee.wire_method),
     GNUNET_PQ_query_param_timestamp (&td->details.wire_fee.start_date),
     GNUNET_PQ_query_param_timestamp (&td->details.wire_fee.end_date),
-    TALER_PQ_query_param_amount (&td->details.wire_fee.fees.wire),
-    TALER_PQ_query_param_amount (&td->details.wire_fee.fees.closing),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.wire_fee.fees.wire),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.wire_fee.fees.closing),
     GNUNET_PQ_query_param_auto_from_type (&td->details.wire_fee.master_sig),
     GNUNET_PQ_query_param_end
   };
@@ -1055,13 +1066,11 @@ irbt_cb_table_wire_fee (struct PostgresClosure *pg,
            ",wire_method"
            ",start_date"
            ",end_date"
-           ",wire_fee_val"
-           ",wire_fee_frac"
-           ",closing_fee_val"
-           ",closing_fee_frac"
+           ",wire_fee"
+           ",closing_fee"
            ",master_sig"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8, $9);");
+           "($1, $2, $3, $4, $5, $6, $7);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_into_table_wire_fee",
                                              params);
@@ -1085,11 +1094,14 @@ irbt_cb_table_global_fee (struct PostgresClosure *pg,
       &td->details.global_fee.start_date),
     GNUNET_PQ_query_param_timestamp (
       &td->details.global_fee.end_date),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.global_fee.fees.history),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.global_fee.fees.account),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.global_fee.fees.purse),
     GNUNET_PQ_query_param_relative_time (
       &td->details.global_fee.purse_timeout),
@@ -1108,18 +1120,15 @@ irbt_cb_table_global_fee (struct PostgresClosure *pg,
            "(global_fee_serial"
            ",start_date"
            ",end_date"
-           ",history_fee_val"
-           ",history_fee_frac"
-           ",account_fee_val"
-           ",account_fee_frac"
-           ",purse_fee_val"
-           ",purse_fee_frac"
+           ",history_fee"
+           ",account_fee"
+           ",purse_fee"
            ",purse_timeout"
            ",history_expiration"
            ",purse_account_limit"
            ",master_sig"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);");
+           "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_into_table_global_fee",
                                              params);
@@ -1140,7 +1149,9 @@ irbt_cb_table_recoup (struct PostgresClosure *pg,
     GNUNET_PQ_query_param_uint64 (&td->serial),
     GNUNET_PQ_query_param_auto_from_type (&td->details.recoup.coin_sig),
     GNUNET_PQ_query_param_auto_from_type (&td->details.recoup.coin_blind),
-    TALER_PQ_query_param_amount (&td->details.recoup.amount),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.recoup.amount),
     GNUNET_PQ_query_param_timestamp (&td->details.recoup.timestamp),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.recoup.coin_pub),
@@ -1154,13 +1165,12 @@ irbt_cb_table_recoup (struct PostgresClosure *pg,
            "(recoup_uuid"
            ",coin_sig"
            ",coin_blind"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            ",recoup_timestamp"
            ",coin_pub"
            ",reserve_out_serial_id"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8);");
+           "($1, $2, $3, $4, $5, $6, $7);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_into_table_recoup",
                                              params);
@@ -1182,7 +1192,9 @@ irbt_cb_table_recoup_refresh (struct PostgresClosure *pg,
     GNUNET_PQ_query_param_auto_from_type 
(&td->details.recoup_refresh.coin_sig),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.recoup_refresh.coin_blind),
-    TALER_PQ_query_param_amount (&td->details.recoup_refresh.amount),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.recoup_refresh.amount),
     GNUNET_PQ_query_param_timestamp (&td->details.recoup_refresh.timestamp),
     GNUNET_PQ_query_param_uint64 (&td->details.recoup_refresh.known_coin_id),
     GNUNET_PQ_query_param_auto_from_type (
@@ -1197,14 +1209,13 @@ irbt_cb_table_recoup_refresh (struct PostgresClosure 
*pg,
            "(recoup_refresh_uuid"
            ",coin_sig"
            ",coin_blind"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            ",recoup_timestamp"
            ",known_coin_id"
            ",coin_pub"
            ",rrc_serial"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8, $9);");
+           "($1, $2, $3, $4, $5, $6, $7, $8);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              
"insert_into_table_recoup_refresh",
                                              params);
@@ -1261,10 +1272,17 @@ irbt_cb_table_policy_details (struct PostgresClosure 
*pg,
     (td->details.policy_details.no_policy_json)
       ? GNUNET_PQ_query_param_null ()
       : TALER_PQ_query_param_json (td->details.policy_details.policy_json),
-    TALER_PQ_query_param_amount (&td->details.policy_details.commitment),
-    TALER_PQ_query_param_amount 
(&td->details.policy_details.accumulated_total),
-    TALER_PQ_query_param_amount (&td->details.policy_details.fee),
-    TALER_PQ_query_param_amount (&td->details.policy_details.transferable),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.policy_details.commitment),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.policy_details.accumulated_total),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.policy_details.fee),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       
&td->details.policy_details.transferable),
     GNUNET_PQ_query_param_timestamp (&td->details.policy_details.deadline),
     GNUNET_PQ_query_param_uint16 (
       &td->details.policy_details.fulfillment_state),
@@ -1282,18 +1300,14 @@ irbt_cb_table_policy_details (struct PostgresClosure 
*pg,
            ",policy_hash_code"
            ",policy_json"
            ",deadline"
-           ",commitment_val"
-           ",commitment_frac"
-           ",accumulated_total_val"
-           ",accumulated_total_frac"
-           ",fee_val"
-           ",fee_frac"
-           ",transferable_val"
-           ",transferable_frac"
+           ",commitment"
+           ",accumulated_total"
+           ",fee"
+           ",transferable"
            ",fulfillment_state"
            ",fulfillment_id"
            ") VALUES "
-           "($1, $2);");
+           "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              
"insert_into_table_policy_details",
                                              params);
@@ -1366,8 +1380,12 @@ irbt_cb_table_purse_requests (struct PostgresClosure *pg,
       &td->details.purse_requests.h_contract_terms),
     GNUNET_PQ_query_param_uint32 (&td->details.purse_requests.age_limit),
     GNUNET_PQ_query_param_uint32 (&td->details.purse_requests.flags),
-    TALER_PQ_query_param_amount (&td->details.purse_requests.amount_with_fee),
-    TALER_PQ_query_param_amount (&td->details.purse_requests.purse_fee),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.purse_requests.amount_with_fee),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.purse_requests.purse_fee),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.purse_requests.purse_sig),
     GNUNET_PQ_query_param_end
@@ -1384,13 +1402,11 @@ irbt_cb_table_purse_requests (struct PostgresClosure 
*pg,
            ",h_contract_terms"
            ",age_limit"
            ",flags"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
-           ",purse_fee_val"
-           ",purse_fee_frac"
+           ",amount_with_fee"
+           ",purse_fee"
            ",purse_sig"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);");
+           "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              
"insert_into_table_purse_requests",
                                              params);
@@ -1488,7 +1504,9 @@ irbt_cb_table_purse_deposits (struct PostgresClosure *pg,
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.purse_deposits.purse_pub),
     GNUNET_PQ_query_param_auto_from_type 
(&td->details.purse_deposits.coin_pub),
-    TALER_PQ_query_param_amount (&td->details.purse_deposits.amount_with_fee),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.purse_deposits.amount_with_fee),
     GNUNET_PQ_query_param_auto_from_type 
(&td->details.purse_deposits.coin_sig),
     GNUNET_PQ_query_param_end
   };
@@ -1500,11 +1518,10 @@ irbt_cb_table_purse_deposits (struct PostgresClosure 
*pg,
            ",partner_serial_id"
            ",purse_pub"
            ",coin_pub"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
+           ",amount_with_fee"
            ",coin_sig"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7);");
+           "($1, $2, $3, $4, $5, $6);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              
"insert_into_table_purse_deposits",
                                              params);
@@ -1568,7 +1585,8 @@ irbt_cb_table_history_requests (struct PostgresClosure 
*pg,
       &td->details.history_requests.request_timestamp),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.history_requests.reserve_sig),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.history_requests.history_fee),
     GNUNET_PQ_query_param_end
   };
@@ -1580,10 +1598,9 @@ irbt_cb_table_history_requests (struct PostgresClosure 
*pg,
            ",reserve_pub"
            ",request_timestamp"
            ",reserve_sig"
-           ",history_fee_val"
-           ",history_fee_frac"
+           ",history_fee"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6);");
+           "($1, $2, $3, $4, $5);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              
"insert_into_table_history_requests",
                                              params);
@@ -1608,9 +1625,11 @@ irbt_cb_table_close_requests (struct PostgresClosure *pg,
       &td->details.close_requests.close_timestamp),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.close_requests.reserve_sig),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.close_requests.close),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.close_requests.close_fee),
     GNUNET_PQ_query_param_string (
       td->details.close_requests.payto_uri),
@@ -1624,13 +1643,11 @@ irbt_cb_table_close_requests (struct PostgresClosure 
*pg,
            ",reserve_pub"
            ",close_timestamp"
            ",reserve_sig"
-           ",close_val"
-           ",close_frac"
-           ",close_fee_val"
-           ",close_fee_frac"
+           ",close"
+           ",close_fee"
            ",payto_uri"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8, $9);");
+           "($1, $2, $3, $4, $5, $6, $7);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              
"insert_into_table_close_requests",
                                              params);
@@ -1651,7 +1668,9 @@ irbt_cb_table_wads_out (struct PostgresClosure *pg,
     GNUNET_PQ_query_param_uint64 (&td->serial),
     GNUNET_PQ_query_param_auto_from_type (&td->details.wads_out.wad_id),
     GNUNET_PQ_query_param_uint64 (&td->details.wads_out.partner_serial_id),
-    TALER_PQ_query_param_amount (&td->details.wads_out.amount),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.wads_out.amount),
     GNUNET_PQ_query_param_timestamp (&td->details.wads_out.execution_time),
     GNUNET_PQ_query_param_end
   };
@@ -1662,11 +1681,10 @@ irbt_cb_table_wads_out (struct PostgresClosure *pg,
            "(wad_out_serial_id"
            ",wad_id"
            ",partner_serial_id"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            ",execution_time"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6);");
+           "($1, $2, $3, $4, $5);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_into_table_wads_out",
                                              params);
@@ -1697,11 +1715,14 @@ irbt_cb_table_wads_out_entries (struct PostgresClosure 
*pg,
       &td->details.wads_out_entries.purse_expiration),
     GNUNET_PQ_query_param_timestamp (
       &td->details.wads_out_entries.merge_timestamp),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.wads_out_entries.amount_with_fee),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.wads_out_entries.wad_fee),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.wads_out_entries.deposit_fees),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.wads_out_entries.reserve_sig),
@@ -1720,16 +1741,13 @@ irbt_cb_table_wads_out_entries (struct PostgresClosure 
*pg,
            ",h_contract"
            ",purse_expiration"
            ",merge_timestamp"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
-           ",wad_fee_val"
-           ",wad_fee_frac"
-           ",deposit_fees_val"
-           ",deposit_fees_frac"
+           ",amount_with_fee"
+           ",wad_fee"
+           ",deposit_fees"
            ",reserve_sig"
            ",purse_sig"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, 
$15);");
+           "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              
"insert_into_table_wads_out_entries",
                                              params);
@@ -1750,7 +1768,9 @@ irbt_cb_table_wads_in (struct PostgresClosure *pg,
     GNUNET_PQ_query_param_uint64 (&td->serial),
     GNUNET_PQ_query_param_auto_from_type (&td->details.wads_in.wad_id),
     GNUNET_PQ_query_param_string (td->details.wads_in.origin_exchange_url),
-    TALER_PQ_query_param_amount (&td->details.wads_in.amount),
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
+      &td->details.wads_in.amount),
     GNUNET_PQ_query_param_timestamp (&td->details.wads_in.arrival_time),
     GNUNET_PQ_query_param_end
   };
@@ -1761,11 +1781,10 @@ irbt_cb_table_wads_in (struct PostgresClosure *pg,
            "(wad_in_serial_id"
            ",wad_id"
            ",origin_exchange_url"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            ",arrival_time"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6);");
+           "($1, $2, $3, $4, $5);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_into_table_wads_in",
                                              params);
@@ -1794,11 +1813,14 @@ irbt_cb_table_wads_in_entries (struct PostgresClosure 
*pg,
       &td->details.wads_in_entries.purse_expiration),
     GNUNET_PQ_query_param_timestamp (
       &td->details.wads_in_entries.merge_timestamp),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.wads_in_entries.amount_with_fee),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.wads_in_entries.wad_fee),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.wads_in_entries.deposit_fees),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.wads_in_entries.reserve_sig),
@@ -1817,16 +1839,13 @@ irbt_cb_table_wads_in_entries (struct PostgresClosure 
*pg,
            ",h_contract"
            ",purse_expiration"
            ",merge_timestamp"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
-           ",wad_fee_val"
-           ",wad_fee_frac"
-           ",deposit_fees_val"
-           ",deposit_fees_frac"
+           ",amount_with_fee"
+           ",wad_fee"
+           ",deposit_fees"
            ",reserve_sig"
            ",purse_sig"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, 
$15);");
+           "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              
"insert_into_table_wads_in_entries",
                                              params);
@@ -1853,7 +1872,8 @@ irbt_cb_table_profit_drains (struct PostgresClosure *pg,
       td->details.profit_drains.payto_uri),
     GNUNET_PQ_query_param_timestamp (
       &td->details.profit_drains.trigger_date),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.profit_drains.amount),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.profit_drains.master_sig),
@@ -1868,11 +1888,10 @@ irbt_cb_table_profit_drains (struct PostgresClosure *pg,
            ",account_section"
            ",payto_uri"
            ",trigger_date"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            ",master_sig"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8);");
+           "($1, $2, $3, $4, $5, $6, $7);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_into_table_profit_drains",
                                              params);
@@ -1939,7 +1958,8 @@ irbt_cb_table_aml_history (struct PostgresClosure *pg,
     GNUNET_PQ_query_param_uint64 (&td->serial),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.aml_history.h_payto),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.aml_history.new_threshold),
     GNUNET_PQ_query_param_uint32 (
       &status32),
@@ -1965,8 +1985,7 @@ irbt_cb_table_aml_history (struct PostgresClosure *pg,
            "INSERT INTO aml_history"
            "(aml_history_serial_id"
            ",h_payto"
-           ",new_threshold_val"
-           ",new_threshold_frac"
+           ",new_threshold"
            ",new_status"
            ",decision_time"
            ",justification"
@@ -1975,7 +1994,7 @@ irbt_cb_table_aml_history (struct PostgresClosure *pg,
            ",decider_pub"
            ",decider_sig"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);");
+           "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_into_table_aml_history",
                                              params);
@@ -2076,7 +2095,8 @@ irbt_cb_table_age_withdraw (struct PostgresClosure *pg,
     GNUNET_PQ_query_param_uint64 (&td->serial),
     GNUNET_PQ_query_param_auto_from_type (
       &td->details.age_withdraw.h_commitment),
-    TALER_PQ_query_param_amount (
+    TALER_PQ_query_param_amount_tuple (
+      pg->conn,
       &td->details.age_withdraw.amount_with_fee),
     GNUNET_PQ_query_param_uint16 (
       &td->details.age_withdraw.max_age),
@@ -2095,14 +2115,13 @@ irbt_cb_table_age_withdraw (struct PostgresClosure *pg,
            "INSERT INTO age_withdraw"
            "(age_withdraw_commitment_id"
            ",h_commitment"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
+           ",amount_with_fee"
            ",max_age"
            ",reserve_pub"
            ",reserve_sig"
            ",noreveal_index"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8, $9);");
+           "($1, $2, $3, $4, $5, $6, $7, $8);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_into_table_age_withdraw",
                                              params);
diff --git a/src/exchangedb/pg_insert_refund.c 
b/src/exchangedb/pg_insert_refund.c
index 02075087..9d35cbfd 100644
--- a/src/exchangedb/pg_insert_refund.c
+++ b/src/exchangedb/pg_insert_refund.c
@@ -37,14 +37,14 @@ TEH_PG_insert_refund (void *cls,
     GNUNET_PQ_query_param_auto_from_type (&refund->details.merchant_sig),
     GNUNET_PQ_query_param_auto_from_type (&refund->details.h_contract_terms),
     GNUNET_PQ_query_param_uint64 (&refund->details.rtransaction_id),
-    TALER_PQ_query_param_amount (&refund->details.refund_amount),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &refund->details.refund_amount),
     GNUNET_PQ_query_param_end
   };
 
   GNUNET_assert (GNUNET_YES ==
                  TALER_amount_cmp_currency (&refund->details.refund_amount,
                                             &refund->details.refund_fee));
-
   PREPARE (pg,
            "insert_refund",
            "INSERT INTO refunds "
@@ -52,9 +52,8 @@ TEH_PG_insert_refund (void *cls,
            ",deposit_serial_id"
            ",merchant_sig"
            ",rtransaction_id"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
-           ") SELECT $1, deposit_serial_id, $3, $5, $6, $7"
+           ",amount_with_fee"
+           ") SELECT $1, deposit_serial_id, $3, $5, $6"
            "    FROM deposits"
            "   WHERE coin_pub=$1"
            "     AND h_contract_terms=$4"
diff --git a/src/exchangedb/pg_insert_reserve_closed.c 
b/src/exchangedb/pg_insert_reserve_closed.c
index 963a3822..58322fe9 100644
--- a/src/exchangedb/pg_insert_reserve_closed.c
+++ b/src/exchangedb/pg_insert_reserve_closed.c
@@ -51,13 +51,14 @@ TEH_PG_insert_reserve_closed (
       GNUNET_PQ_query_param_timestamp (&execution_date),
       GNUNET_PQ_query_param_auto_from_type (wtid),
       GNUNET_PQ_query_param_auto_from_type (&h_payto),
-      TALER_PQ_query_param_amount (amount_with_fee),
-      TALER_PQ_query_param_amount (closing_fee),
+      TALER_PQ_query_param_amount_tuple (pg->conn,
+                                         amount_with_fee),
+      TALER_PQ_query_param_amount_tuple (pg->conn,
+                                         closing_fee),
       GNUNET_PQ_query_param_uint64 (&close_request_row),
       GNUNET_PQ_query_param_end
     };
 
-    /* Used in #postgres_insert_reserve_closed() */
     PREPARE (pg,
              "reserves_close_insert",
              "INSERT INTO reserves_close "
@@ -65,12 +66,10 @@ TEH_PG_insert_reserve_closed (
              ",execution_date"
              ",wtid"
              ",wire_target_h_payto"
-             ",amount_val"
-             ",amount_frac"
-             ",closing_fee_val"
-             ",closing_fee_frac"
+             ",amount"
+             ",closing_fee"
              ",close_request_row"
-             ") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);");
+             ") VALUES ($1, $2, $3, $4, $5, $6, $7);");
 
     qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "reserves_close_insert",
diff --git a/src/exchangedb/pg_insert_reserve_open_deposit.c 
b/src/exchangedb/pg_insert_reserve_open_deposit.c
index 8bf70e7b..25fbcbde 100644
--- a/src/exchangedb/pg_insert_reserve_open_deposit.c
+++ b/src/exchangedb/pg_insert_reserve_open_deposit.c
@@ -44,7 +44,8 @@ TEH_PG_insert_reserve_open_deposit (
     GNUNET_PQ_query_param_auto_from_type (coin_sig),
     GNUNET_PQ_query_param_auto_from_type (reserve_sig),
     GNUNET_PQ_query_param_auto_from_type (reserve_pub),
-    TALER_PQ_query_param_amount (coin_total),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       coin_total),
     GNUNET_PQ_query_param_end
   };
   struct GNUNET_PQ_ResultSpec rs[] = {
@@ -58,7 +59,7 @@ TEH_PG_insert_reserve_open_deposit (
            "SELECT "
            " out_insufficient_funds"
            " FROM exchange_do_reserve_open_deposit"
-           " ($1,$2,$3,$4,$5,$6,$7);");
+           " ($1,$2,$3,$4,$5,$6);");
   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
                                                    
"insert_reserve_open_deposit",
                                                    params,
diff --git a/src/exchangedb/pg_insert_wire_fee.c 
b/src/exchangedb/pg_insert_wire_fee.c
index 6d94e3d5..b6070c92 100644
--- a/src/exchangedb/pg_insert_wire_fee.c
+++ b/src/exchangedb/pg_insert_wire_fee.c
@@ -40,8 +40,10 @@ TEH_PG_insert_wire_fee (void *cls,
     GNUNET_PQ_query_param_string (type),
     GNUNET_PQ_query_param_timestamp (&start_date),
     GNUNET_PQ_query_param_timestamp (&end_date),
-    TALER_PQ_query_param_amount (&fees->wire),
-    TALER_PQ_query_param_amount (&fees->closing),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &fees->wire),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &fees->closing),
     GNUNET_PQ_query_param_auto_from_type (master_sig),
     GNUNET_PQ_query_param_end
   };
@@ -89,20 +91,17 @@ TEH_PG_insert_wire_fee (void *cls,
     return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
   }
 
-  /* Used in #postgres_insert_wire_fee */
   PREPARE (pg,
            "insert_wire_fee",
            "INSERT INTO wire_fee "
            "(wire_method"
            ",start_date"
            ",end_date"
-           ",wire_fee_val"
-           ",wire_fee_frac"
-           ",closing_fee_val"
-           ",closing_fee_frac"
+           ",wire_fee"
+           ",closing_fee"
            ",master_sig"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6, $7, $8);");
+           "($1, $2, $3, $4, $5, $6);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_wire_fee",
                                              params);
diff --git a/src/exchangedb/pg_iterate_denomination_info.c 
b/src/exchangedb/pg_iterate_denomination_info.c
index ba7026eb..cab51d5c 100644
--- a/src/exchangedb/pg_iterate_denomination_info.c
+++ b/src/exchangedb/pg_iterate_denomination_info.c
@@ -155,7 +155,6 @@ TEH_PG_iterate_denomination_info (void *cls,
     .pg = pg
   };
 
-  /* Used in #postgres_iterate_denomination_info() */
   PREPARE (pg,
            "denomination_iterate",
            "SELECT"
@@ -165,16 +164,11 @@ TEH_PG_iterate_denomination_info (void *cls,
            ",expire_withdraw"
            ",expire_deposit"
            ",expire_legal"
-           ",coin_val"                                                /* value 
of this denom */
-           ",coin_frac"                                                /* 
fractional value of this denom */
-           ",fee_withdraw_val"
-           ",fee_withdraw_frac"
-           ",fee_deposit_val"
-           ",fee_deposit_frac"
-           ",fee_refresh_val"
-           ",fee_refresh_frac"
-           ",fee_refund_val"
-           ",fee_refund_frac"
+           ",coin" /* value of this denom */
+           ",fee_withdraw"
+           ",fee_deposit"
+           ",fee_refresh"
+           ",fee_refund"
            ",denom_pub"
            ",age_mask"
            " FROM denominations;");
diff --git a/src/exchangedb/pg_iterate_denominations.c 
b/src/exchangedb/pg_iterate_denominations.c
index 1549ed77..684aa165 100644
--- a/src/exchangedb/pg_iterate_denominations.c
+++ b/src/exchangedb/pg_iterate_denominations.c
@@ -143,7 +143,6 @@ TEH_PG_iterate_denominations (void *cls,
     .pg = pg
   };
 
-  /* Used in #postgres_iterate_denominations() */
   PREPARE (pg,
            "select_denominations",
            "SELECT"
@@ -154,24 +153,17 @@ TEH_PG_iterate_denominations (void *cls,
            ",expire_withdraw"
            ",expire_deposit"
            ",expire_legal"
-           ",coin_val"                                                /* value 
of this denom */
-           ",coin_frac"                                                /* 
fractional value of this denom */
-           ",fee_withdraw_val"
-           ",fee_withdraw_frac"
-           ",fee_deposit_val"
-           ",fee_deposit_frac"
-           ",fee_refresh_val"
-           ",fee_refresh_frac"
-           ",fee_refund_val"
-           ",fee_refund_frac"
+           ",coin"              /* value of this denom */
+           ",fee_withdraw"
+           ",fee_deposit"
+           ",fee_refresh"
+           ",fee_refund"
            ",denom_type"
            ",age_mask"
            ",denom_pub"
            " FROM denominations"
            " LEFT JOIN "
            "   denomination_revocations USING (denominations_serial);");
-
-
   return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
                                                "select_denominations",
                                                params,
diff --git a/src/exchangedb/pg_iterate_reserve_close_info.c 
b/src/exchangedb/pg_iterate_reserve_close_info.c
index f1b2d452..ff0a813c 100644
--- a/src/exchangedb/pg_iterate_reserve_close_info.c
+++ b/src/exchangedb/pg_iterate_reserve_close_info.c
@@ -113,8 +113,7 @@ TEH_PG_iterate_reserve_close_info (
   PREPARE (pg,
            "iterate_reserve_close_info",
            "SELECT"
-           " amount_val"
-           ",amount_frac"
+           " amount"
            ",execution_date"
            " FROM reserves_close"
            " WHERE wire_target_h_payto=$1"
diff --git a/src/exchangedb/pg_lookup_denomination_key.c 
b/src/exchangedb/pg_lookup_denomination_key.c
index 759af1b5..20eb703d 100644
--- a/src/exchangedb/pg_lookup_denomination_key.c
+++ b/src/exchangedb/pg_lookup_denomination_key.c
@@ -68,16 +68,11 @@ TEH_PG_lookup_denomination_key (
            ",expire_withdraw"
            ",expire_deposit"
            ",expire_legal"
-           ",coin_val"
-           ",coin_frac"
-           ",fee_withdraw_val"
-           ",fee_withdraw_frac"
-           ",fee_deposit_val"
-           ",fee_deposit_frac"
-           ",fee_refresh_val"
-           ",fee_refresh_frac"
-           ",fee_refund_val"
-           ",fee_refund_frac"
+           ",coin"
+           ",fee_withdraw"
+           ",fee_deposit"
+           ",fee_refresh"
+           ",fee_refund"
            ",age_mask"
            " FROM denominations"
            " WHERE denom_pub_hash=$1;");
diff --git a/src/exchangedb/pg_lookup_global_fee_by_time.c 
b/src/exchangedb/pg_lookup_global_fee_by_time.c
index 0119c2cd..c3a6ec8b 100644
--- a/src/exchangedb/pg_lookup_global_fee_by_time.c
+++ b/src/exchangedb/pg_lookup_global_fee_by_time.c
@@ -165,12 +165,9 @@ TEH_PG_lookup_global_fee_by_time (
   PREPARE (pg,
            "lookup_global_fee_by_time",
            "SELECT"
-           " history_fee_val"
-           ",history_fee_frac"
-           ",account_fee_val"
-           ",account_fee_frac"
-           ",purse_fee_val"
-           ",purse_fee_frac"
+           " history_fee"
+           ",account_fee"
+           ",purse_fee"
            ",purse_timeout"
            ",history_expiration"
            ",purse_account_limit"
diff --git a/src/exchangedb/pg_lookup_records_by_table.c 
b/src/exchangedb/pg_lookup_records_by_table.c
index aec8cb61..92378c3f 100644
--- a/src/exchangedb/pg_lookup_records_by_table.c
+++ b/src/exchangedb/pg_lookup_records_by_table.c
@@ -2872,16 +2872,11 @@ TEH_PG_lookup_records_by_table (void *cls,
               ",expire_withdraw"
               ",expire_deposit"
               ",expire_legal"
-              ",coin_val"
-              ",coin_frac"
-              ",fee_withdraw_val"
-              ",fee_withdraw_frac"
-              ",fee_deposit_val"
-              ",fee_deposit_frac"
-              ",fee_refresh_val"
-              ",fee_refresh_frac"
-              ",fee_refund_val"
-              ",fee_refund_frac"
+              ",coin"
+              ",fee_withdraw"
+              ",fee_deposit"
+              ",fee_refresh"
+              ",fee_refund"
               ",age_mask"
               " FROM denominations"
               " WHERE denominations_serial > $1"
@@ -2954,8 +2949,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               " reserve_in_serial_id AS serial"
               ",reserve_pub"
               ",wire_reference"
-              ",credit_val"
-              ",credit_frac"
+              ",credit"
               ",wire_source_h_payto"
               ",exchange_account_section"
               ",execution_date"
@@ -2972,10 +2966,8 @@ TEH_PG_lookup_records_by_table (void *cls,
               ",execution_date"
               ",wtid"
               ",wire_target_h_payto"
-              ",amount_val"
-              ",amount_frac"
-              ",closing_fee_val"
-              ",closing_fee_frac"
+              ",amount"
+              ",closing_fee"
               " FROM reserves_close"
               " WHERE close_uuid > $1"
               " ORDER BY close_uuid ASC;");
@@ -2989,8 +2981,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               ",request_timestamp"
               ",expiration_date"
               ",reserve_sig"
-              ",reserve_payment_val"
-              ",reserve_payment_frac"
+              ",reserve_payment"
               ",requested_purse_limit"
               " FROM reserves_open_requests"
               " WHERE open_request_uuid > $1"
@@ -3005,8 +2996,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               ",reserve_pub"
               ",coin_pub"
               ",coin_sig"
-              ",contribution_val"
-              ",contribution_frac"
+              ",contribution"
               " FROM reserves_open_deposits"
               " WHERE reserves_open_deposit_uuid > $1"
               " ORDER BY reserves_open_deposit_uuid ASC;");
@@ -3022,8 +3012,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               ",reserve_uuid"
               ",reserve_sig"
               ",execution_date"
-              ",amount_with_fee_val"
-              ",amount_with_fee_frac"
+              ",amount_with_fee"
               " FROM reserves_out"
               " JOIN reserves USING (reserve_uuid)"
               " WHERE reserve_out_serial_id > $1"
@@ -3099,8 +3088,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               " melt_serial_id AS serial"
               ",rc"
               ",old_coin_sig"
-              ",amount_with_fee_val"
-              ",amount_with_fee_frac"
+              ",amount_with_fee"
               ",noreveal_index"
               ",old_coin_pub"
               " FROM refresh_commitments"
@@ -3143,8 +3131,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               ",shard"
               ",coin_pub"
               ",known_coin_id"
-              ",amount_with_fee_val"
-              ",amount_with_fee_frac"
+              ",amount_with_fee"
               ",wallet_timestamp"
               ",exchange_timestamp"
               ",refund_deadline"
@@ -3169,8 +3156,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               ",coin_pub"
               ",merchant_sig"
               ",rtransaction_id"
-              ",amount_with_fee_val"
-              ",amount_with_fee_frac"
+              ",amount_with_fee"
               ",deposit_serial_id"
               " FROM refunds"
               " WHERE refund_serial_id > $1"
@@ -3185,8 +3171,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               ",wtid_raw"
               ",wire_target_h_payto"
               ",exchange_account_section"
-              ",amount_val"
-              ",amount_frac"
+              ",amount"
               " FROM wire_out"
               " WHERE wireout_uuid > $1"
               " ORDER BY wireout_uuid ASC;");
@@ -3210,10 +3195,8 @@ TEH_PG_lookup_records_by_table (void *cls,
               ",wire_method"
               ",start_date"
               ",end_date"
-              ",wire_fee_val"
-              ",wire_fee_frac"
-              ",closing_fee_val"
-              ",closing_fee_frac"
+              ",wire_fee"
+              ",closing_fee"
               ",master_sig"
               " FROM wire_fee"
               " WHERE wire_fee_serial > $1"
@@ -3226,12 +3209,9 @@ TEH_PG_lookup_records_by_table (void *cls,
               " global_fee_serial AS serial"
               ",start_date"
               ",end_date"
-              ",history_fee_val"
-              ",history_fee_frac"
-              ",account_fee_val"
-              ",account_fee_frac"
-              ",purse_fee_val"
-              ",purse_fee_frac"
+              ",history_fee"
+              ",account_fee"
+              ",purse_fee"
               ",purse_timeout"
               ",history_expiration"
               ",purse_account_limit"
@@ -3247,8 +3227,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               " recoup_uuid AS serial"
               ",coin_sig"
               ",coin_blind"
-              ",amount_val"
-              ",amount_frac"
+              ",amount"
               ",recoup_timestamp"
               ",coin_pub"
               ",reserve_out_serial_id"
@@ -3263,8 +3242,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               " recoup_refresh_uuid AS serial"
               ",coin_sig"
               ",coin_blind"
-              ",amount_val"
-              ",amount_frac"
+              ",amount"
               ",recoup_timestamp"
               ",coin_pub"
               ",known_coin_id"
@@ -3297,10 +3275,8 @@ TEH_PG_lookup_records_by_table (void *cls,
               ",h_contract_terms"
               ",age_limit"
               ",flags"
-              ",amount_with_fee_val"
-              ",amount_with_fee_frac"
-              ",purse_fee_val"
-              ",purse_fee_frac"
+              ",amount_with_fee"
+              ",purse_fee"
               ",purse_sig"
               " FROM purse_requests"
               " WHERE purse_requests_serial_id > $1"
@@ -3340,8 +3316,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               ",partner_serial_id"
               ",purse_pub"
               ",coin_pub"
-              ",amount_with_fee_val"
-              ",amount_with_fee_frac"
+              ",amount_with_fee"
               ",coin_sig"
               " FROM purse_deposits"
               " WHERE purse_deposit_serial_id > $1"
@@ -3368,8 +3343,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               ",reserve_pub"
               ",request_timestamp"
               ",reserve_sig"
-              ",history_fee_val"
-              ",history_fee_frac"
+              ",history_fee"
               " FROM history_requests"
               " WHERE history_request_serial_id > $1"
               " ORDER BY history_request_serial_id ASC;");
@@ -3382,8 +3356,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               ",reserve_pub"
               ",close_timestamp"
               ",reserve_sig"
-              ",close_val"
-              ",close_frac"
+              ",close"
               " FROM close_requests"
               " WHERE close_request_serial_id > $1"
               " ORDER BY close_request_serial_id ASC;");
@@ -3395,8 +3368,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               " wad_out_serial_id"
               ",wad_id"
               ",partner_serial_id"
-              ",amount_val"
-              ",amount_frac"
+              ",amount"
               ",execution_time"
               " FROM wads_out"
               " WHERE wad_out_serial_id > $1"
@@ -3412,12 +3384,9 @@ TEH_PG_lookup_records_by_table (void *cls,
               ",h_contract"
               ",purse_expiration"
               ",merge_timestamp"
-              ",amount_with_fee_val"
-              ",amount_with_fee_frac"
-              ",wad_fee_val"
-              ",wad_fee_frac"
-              ",deposit_fees_val"
-              ",deposit_fees_frac"
+              ",amount_with_fee"
+              ",wad_fee"
+              ",deposit_fees"
               ",reserve_sig"
               ",purse_sig"
               " FROM wad_out_entries"
@@ -3431,8 +3400,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               " wad_in_serial_id"
               ",wad_id"
               ",origin_exchange_url"
-              ",amount_val"
-              ",amount_frac"
+              ",amount"
               ",arrival_time"
               " FROM wads_in"
               " WHERE wad_in_serial_id > $1"
@@ -3448,12 +3416,9 @@ TEH_PG_lookup_records_by_table (void *cls,
               ",h_contract"
               ",purse_expiration"
               ",merge_timestamp"
-              ",amount_with_fee_val"
-              ",amount_with_fee_frac"
-              ",wad_fee_val"
-              ",wad_fee_frac"
-              ",deposit_fees_val"
-              ",deposit_fees_frac"
+              ",amount_with_fee"
+              ",wad_fee"
+              ",deposit_fees"
               ",reserve_sig"
               ",purse_sig"
               " FROM wad_in_entries"
@@ -3469,8 +3434,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               ",account_section"
               ",payto_uri"
               ",trigger_date"
-              ",amount_val"
-              ",amount_frac"
+              ",amount"
               ",master_sig"
               " FROM profit_drains"
               " WHERE profit_drain_serial_id > $1"
@@ -3498,8 +3462,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               "SELECT"
               " aml_history_serial_id"
               ",h_payto"
-              ",new_threshold_val"
-              ",new_threshold_frac"
+              ",new_threshold"
               ",new_status"
               ",decision_time"
               ",justification"
@@ -3543,8 +3506,7 @@ TEH_PG_lookup_records_by_table (void *cls,
               "SELECT"
               " age_withdraw_id"
               ",h_commitment"
-              ",amount_with_fee_val"
-              ",amount_with_fee_frac"
+              ",amount_with_fee"
               ",max_age"
               ",reserve_pub"
               ",reserve_sig"
diff --git a/src/exchangedb/pg_lookup_transfer_by_deposit.c 
b/src/exchangedb/pg_lookup_transfer_by_deposit.c
index a9de0dd6..5a304358 100644
--- a/src/exchangedb/pg_lookup_transfer_by_deposit.c
+++ b/src/exchangedb/pg_lookup_transfer_by_deposit.c
@@ -76,12 +76,10 @@ TEH_PG_lookup_transfer_by_deposit (
            "SELECT"
            " aggregation_tracking.wtid_raw"
            ",wire_out.execution_date"
-           ",dep.amount_with_fee_val"
-           ",dep.amount_with_fee_frac"
+           ",dep.amount_with_fee"
            ",dep.wire_salt"
            ",wt.payto_uri"
-           ",denom.fee_deposit_val"
-           ",denom.fee_deposit_frac"
+           ",denom.fee_deposit"
            " FROM deposits dep"
            "    JOIN wire_targets wt"
            "      USING (wire_target_h_payto)"
@@ -167,10 +165,8 @@ TEH_PG_lookup_transfer_by_deposit (
              " agt.legitimization_requirement_serial_id"
              ",dep.wire_salt"
              ",wt.payto_uri"
-             ",dep.amount_with_fee_val"
-             ",dep.amount_with_fee_frac"
-             ",denom.fee_deposit_val"
-             ",denom.fee_deposit_frac"
+             ",dep.amount_with_fee"
+             ",denom.fee_deposit"
              ",dep.wire_deadline"
              ",aml.status"
              ",aml.kyc_requirement"
diff --git a/src/exchangedb/pg_lookup_wire_fee_by_time.c 
b/src/exchangedb/pg_lookup_wire_fee_by_time.c
index 89be4087..775232a4 100644
--- a/src/exchangedb/pg_lookup_wire_fee_by_time.c
+++ b/src/exchangedb/pg_lookup_wire_fee_by_time.c
@@ -142,10 +142,8 @@ TEH_PG_lookup_wire_fee_by_time (
   PREPARE (pg,
            "lookup_wire_fee_by_time",
            "SELECT"
-           " wire_fee_val"
-           ",wire_fee_frac"
-           ",closing_fee_val"
-           ",closing_fee_frac"
+           " wire_fee"
+           ",closing_fee"
            " FROM wire_fee"
            " WHERE wire_method=$1"
            " AND end_date > $2"
diff --git a/src/exchangedb/pg_lookup_wire_transfer.c 
b/src/exchangedb/pg_lookup_wire_transfer.c
index 5d1ad25f..500ec289 100644
--- a/src/exchangedb/pg_lookup_wire_transfer.c
+++ b/src/exchangedb/pg_lookup_wire_transfer.c
@@ -159,10 +159,8 @@ TEH_PG_lookup_wire_transfer (
            ",kc.coin_pub"
            ",deposits.merchant_pub"
            ",wire_out.execution_date"
-           ",deposits.amount_with_fee_val"
-           ",deposits.amount_with_fee_frac"
-           ",denom.fee_deposit_val"
-           ",denom.fee_deposit_frac"
+           ",deposits.amount_with_fee"
+           ",denom.fee_deposit"
            ",denom.denom_pub"
            " FROM aggregation_tracking"
            "    JOIN deposits"
diff --git a/src/exchangedb/pg_persist_policy_details.c 
b/src/exchangedb/pg_persist_policy_details.c
index 3bc7afa9..7db31039 100644
--- a/src/exchangedb/pg_persist_policy_details.c
+++ b/src/exchangedb/pg_persist_policy_details.c
@@ -39,10 +39,14 @@ TEH_PG_persist_policy_details (
     GNUNET_PQ_query_param_auto_from_type (&details->hash_code),
     TALER_PQ_query_param_json (details->policy_json),
     GNUNET_PQ_query_param_timestamp (&details->deadline),
-    TALER_PQ_query_param_amount (&details->commitment),
-    TALER_PQ_query_param_amount (&details->accumulated_total),
-    TALER_PQ_query_param_amount (&details->policy_fee),
-    TALER_PQ_query_param_amount (&details->transferable_amount),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &details->commitment),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &details->accumulated_total),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &details->policy_fee),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       &details->transferable_amount),
     GNUNET_PQ_query_param_auto_from_type (&details->fulfillment_state),
     (details->no_policy_fulfillment_id)
      ?  GNUNET_PQ_query_param_null ()
@@ -63,11 +67,10 @@ TEH_PG_persist_policy_details (
            "call_insert_or_update_policy_details",
            "SELECT"
            " out_policy_details_serial_id AS policy_details_serial_id"
-           ",out_accumulated_total_val AS accumulated_total_val"
-           ",out_accumulated_total_frac AS accumulated_total_frac"
+           ",out_accumulated_total AS accumulated_total"
            ",out_fulfillment_state AS fulfillment_state"
            " FROM exchange_do_insert_or_update_policy_details"
-           "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);");
+           "($1, $2, $3, $4, $5, $6, $7, $8, $9);");
   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
                                                    
"call_insert_or_update_policy_details",
                                                    params,
diff --git a/src/exchangedb/pg_profit_drains_get_pending.c 
b/src/exchangedb/pg_profit_drains_get_pending.c
index f4a5d451..c844a3f3 100644
--- a/src/exchangedb/pg_profit_drains_get_pending.c
+++ b/src/exchangedb/pg_profit_drains_get_pending.c
@@ -66,8 +66,7 @@ TEH_PG_profit_drains_get_pending (
            ",account_section"
            ",payto_uri"
            ",trigger_date"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            ",master_sig"
            " FROM profit_drains"
            " WHERE NOT executed"
diff --git a/src/exchangedb/pg_select_account_merges_above_serial_id.c 
b/src/exchangedb/pg_select_account_merges_above_serial_id.c
index 95c2f93a..6c3c8112 100644
--- a/src/exchangedb/pg_select_account_merges_above_serial_id.c
+++ b/src/exchangedb/pg_select_account_merges_above_serial_id.c
@@ -168,12 +168,10 @@ TEH_PG_select_account_merges_above_serial_id (
            ",am.purse_pub"
            ",pr.h_contract_terms"
            ",pr.purse_expiration"
-           ",pr.amount_with_fee_val"
-           ",pr.amount_with_fee_frac"
+           ",pr.amount_with_fee"
            ",pr.age_limit"
            ",pr.flags"
-           ",pr.purse_fee_val"
-           ",pr.purse_fee_frac"
+           ",pr.purse_fee"
            ",pm.merge_timestamp"
            ",am.reserve_sig"
            " FROM account_merges am"
diff --git a/src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.c 
b/src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.c
index d24c6245..0d5d0ee2 100644
--- a/src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.c
+++ b/src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.c
@@ -135,8 +135,7 @@ TEH_PG_select_aggregation_amounts_for_kyc_check (
   PREPARE (pg,
            "select_kyc_relevant_aggregation_events",
            "SELECT"
-           " amount_val"
-           ",amount_frac"
+           " amount"
            ",execution_date AS date"
            " FROM wire_out"
            " WHERE wire_target_h_payto=$1"
diff --git a/src/exchangedb/pg_select_aggregation_transient.c 
b/src/exchangedb/pg_select_aggregation_transient.c
index d8d7ae70..f9b6193e 100644
--- a/src/exchangedb/pg_select_aggregation_transient.c
+++ b/src/exchangedb/pg_select_aggregation_transient.c
@@ -53,8 +53,7 @@ TEH_PG_select_aggregation_transient (
   PREPARE (pg,
            "select_aggregation_transient",
            "SELECT"
-           "  amount_val"
-           " ,amount_frac"
+           "  amount"
            " ,wtid_raw"
            " FROM aggregation_transient"
            " WHERE wire_target_h_payto=$1"
diff --git a/src/exchangedb/pg_select_aml_history.c 
b/src/exchangedb/pg_select_aml_history.c
index c54a3ef0..0461e0d9 100644
--- a/src/exchangedb/pg_select_aml_history.c
+++ b/src/exchangedb/pg_select_aml_history.c
@@ -138,8 +138,7 @@ TEH_PG_select_aml_history (
   PREPARE (pg,
            "lookup_aml_history",
            "SELECT"
-           " new_threshold_val"
-           ",new_threshold_frac"
+           " new_threshold"
            ",new_status"
            ",decision_time"
            ",justification"
diff --git a/src/exchangedb/pg_select_aml_process.c 
b/src/exchangedb/pg_select_aml_process.c
index 5df5fe65..c34cae4b 100644
--- a/src/exchangedb/pg_select_aml_process.c
+++ b/src/exchangedb/pg_select_aml_process.c
@@ -140,8 +140,7 @@ TEH_PG_select_aml_process (
            "SELECT"
            " aml_status_serial_id"
            ",h_payto"
-           ",threshold_val"
-           ",threshold_frac"
+           ",threshold"
            ",status"
            " FROM aml_status"
            " WHERE aml_status_serial_id > $2"
@@ -153,8 +152,7 @@ TEH_PG_select_aml_process (
            "SELECT"
            " aml_status_serial_id"
            ",h_payto"
-           ",threshold_val"
-           ",threshold_frac"
+           ",threshold"
            ",status"
            " FROM aml_status"
            " WHERE aml_status_serial_id < $2"
diff --git a/src/exchangedb/pg_select_aml_threshold.c 
b/src/exchangedb/pg_select_aml_threshold.c
index f78a71ff..23286f02 100644
--- a/src/exchangedb/pg_select_aml_threshold.c
+++ b/src/exchangedb/pg_select_aml_threshold.c
@@ -54,8 +54,7 @@ TEH_PG_select_aml_threshold (
   PREPARE (pg,
            "select_aml_threshold",
            "SELECT"
-           " threshold_val"
-           ",threshold_frac"
+           " threshold"
            ",status"
            ",kyc_requirement"
            " FROM aml_status"
diff --git a/src/exchangedb/pg_select_deposits_above_serial_id.c 
b/src/exchangedb/pg_select_deposits_above_serial_id.c
index b3258bd4..102604f2 100644
--- a/src/exchangedb/pg_select_deposits_above_serial_id.c
+++ b/src/exchangedb/pg_select_deposits_above_serial_id.c
@@ -162,8 +162,7 @@ TEH_PG_select_deposits_above_serial_id (
   PREPARE (pg,
            "audit_get_deposits_incr",
            "SELECT"
-           " amount_with_fee_val"
-           ",amount_with_fee_frac"
+           " amount_with_fee"
            ",wallet_timestamp"
            ",exchange_timestamp"
            ",merchant_pub"
diff --git a/src/exchangedb/pg_select_deposits_missing_wire.c 
b/src/exchangedb/pg_select_deposits_missing_wire.c
index e638c88e..a18a7abf 100644
--- a/src/exchangedb/pg_select_deposits_missing_wire.c
+++ b/src/exchangedb/pg_select_deposits_missing_wire.c
@@ -143,8 +143,7 @@ TEH_PG_select_deposits_missing_wire (void *cls,
            "SELECT"
            " deposit_serial_id"
            ",coin_pub"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
+           ",amount_with_fee"
            ",payto_uri"
            ",wire_deadline"
            ",done"
diff --git a/src/exchangedb/pg_select_history_requests_above_serial_id.c 
b/src/exchangedb/pg_select_history_requests_above_serial_id.c
index 36902e0a..2ff2f989 100644
--- a/src/exchangedb/pg_select_history_requests_above_serial_id.c
+++ b/src/exchangedb/pg_select_history_requests_above_serial_id.c
@@ -136,8 +136,7 @@ TEH_PG_select_history_requests_above_serial_id (
            "audit_get_history_requests_incr",
            "SELECT"
            " history_request_serial_id"
-           ",history_fee_val"
-           ",history_fee_frac"
+           ",history_fee"
            ",request_timestamp"
            ",reserve_pub"
            ",reserve_sig"
diff --git a/src/exchangedb/pg_select_merge_amounts_for_kyc_check.c 
b/src/exchangedb/pg_select_merge_amounts_for_kyc_check.c
index b1bdd145..417d78ec 100644
--- a/src/exchangedb/pg_select_merge_amounts_for_kyc_check.c
+++ b/src/exchangedb/pg_select_merge_amounts_for_kyc_check.c
@@ -135,8 +135,7 @@ TEH_PG_select_merge_amounts_for_kyc_check (
   PREPARE (pg,
            "select_kyc_relevant_merge_events",
            "SELECT"
-           " amount_with_fee_val AS amount_val"
-           ",amount_with_fee_frac AS amount_frac"
+           " amount_with_fee AS amount"
            ",merge_timestamp AS date"
            " FROM account_merges"
            " JOIN purse_merges USING (purse_pub)"
diff --git a/src/exchangedb/pg_select_purse.c b/src/exchangedb/pg_select_purse.c
index 6496d4a2..7c0a638a 100644
--- a/src/exchangedb/pg_select_purse.c
+++ b/src/exchangedb/pg_select_purse.c
@@ -70,10 +70,8 @@ TEH_PG_select_purse (
            ",pr.purse_creation"
            ",pr.purse_expiration"
            ",pr.h_contract_terms"
-           ",pr.amount_with_fee_val"
-           ",pr.amount_with_fee_frac"
-           ",pr.balance_val"
-           ",pr.balance_frac"
+           ",pr.amount_with_fee"
+           ",pr.balance"
            ",pm.merge_timestamp"
            ",pd.purse_sig IS NOT NULL AS purse_deleted"
            " FROM purse_requests pr"
diff --git a/src/exchangedb/pg_select_purse_by_merge_pub.c 
b/src/exchangedb/pg_select_purse_by_merge_pub.c
index 965b27ba..d035b325 100644
--- a/src/exchangedb/pg_select_purse_by_merge_pub.c
+++ b/src/exchangedb/pg_select_purse_by_merge_pub.c
@@ -60,7 +60,6 @@ TEH_PG_select_purse_by_merge_pub (
     GNUNET_PQ_result_spec_end
   };
 
-
   PREPARE (pg,
            "select_purse_by_merge_pub",
            "SELECT "
@@ -68,14 +67,11 @@ TEH_PG_select_purse_by_merge_pub (
            ",purse_expiration"
            ",h_contract_terms"
            ",age_limit"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
-           ",balance_val"
-           ",balance_frac"
+           ",amount_with_fee"
+           ",balance"
            ",purse_sig"
            " FROM purse_requests"
            " WHERE merge_pub=$1;");
-
   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
                                                    "select_purse_by_merge_pub",
                                                    params,
diff --git a/src/exchangedb/pg_select_purse_decisions_above_serial_id.c 
b/src/exchangedb/pg_select_purse_decisions_above_serial_id.c
index 02e67197..f301ea78 100644
--- a/src/exchangedb/pg_select_purse_decisions_above_serial_id.c
+++ b/src/exchangedb/pg_select_purse_decisions_above_serial_id.c
@@ -140,8 +140,7 @@ TEH_PG_select_purse_decisions_above_serial_id (
            " pd.purse_pub"
            ",pm.reserve_pub"
            ",pd.purse_decision_serial_id"
-           ",pr.amount_with_fee_val"
-           ",pr.amount_with_fee_frac"
+           ",pr.amount_with_fee"
            " FROM purse_decision pd"
            " JOIN purse_requests pr ON (pd.purse_pub = pr.purse_pub)"
            " LEFT JOIN purse_merges pm ON (pm.purse_pub = pd.purse_pub)"
diff --git a/src/exchangedb/pg_select_purse_deposits_above_serial_id.c 
b/src/exchangedb/pg_select_purse_deposits_above_serial_id.c
index 72fdcd99..bb432066 100644
--- a/src/exchangedb/pg_select_purse_deposits_above_serial_id.c
+++ b/src/exchangedb/pg_select_purse_deposits_above_serial_id.c
@@ -168,12 +168,9 @@ TEH_PG_select_purse_deposits_above_serial_id (
   PREPARE (pg,
            "audit_get_purse_deposits_incr",
            "SELECT"
-           " pd.amount_with_fee_val"
-           ",pd.amount_with_fee_frac"
-           ",pr.amount_with_fee_val AS total_val"
-           ",pr.amount_with_fee_frac AS total_frac"
-           ",pr.balance_val"
-           ",pr.balance_frac"
+           " pd.amount_with_fee"
+           ",pr.amount_with_fee AS total"
+           ",pr.balance"
            ",pr.flags"
            ",pd.purse_pub"
            ",pd.coin_sig"
diff --git a/src/exchangedb/pg_select_purse_deposits_by_purse.c 
b/src/exchangedb/pg_select_purse_deposits_by_purse.c
index 5fe7e014..cfc72a44 100644
--- a/src/exchangedb/pg_select_purse_deposits_by_purse.c
+++ b/src/exchangedb/pg_select_purse_deposits_by_purse.c
@@ -133,8 +133,7 @@ TEH_PG_select_purse_deposits_by_purse (
            "audit_get_purse_deposits_by_purse",
            "SELECT"
            " pd.purse_deposit_serial_id"
-           ",pd.amount_with_fee_val"
-           ",pd.amount_with_fee_frac"
+           ",pd.amount_with_fee"
            ",pd.coin_pub"
            ",denom.denom_pub"
            " FROM purse_deposits pd"
diff --git a/src/exchangedb/pg_select_purse_merges_above_serial_id.c 
b/src/exchangedb/pg_select_purse_merges_above_serial_id.c
index 748a92b7..cd06d65e 100644
--- a/src/exchangedb/pg_select_purse_merges_above_serial_id.c
+++ b/src/exchangedb/pg_select_purse_merges_above_serial_id.c
@@ -163,10 +163,8 @@ TEH_PG_select_purse_merges_above_serial_id (
            "SELECT"
            " pm.purse_merge_request_serial_id"
            ",partner_base_url"
-           ",pr.amount_with_fee_val"
-           ",pr.amount_with_fee_frac"
-           ",pr.balance_val"
-           ",pr.balance_frac"
+           ",pr.amount_with_fee"
+           ",pr.balance"
            ",pr.flags"
            ",pr.merge_pub"
            ",pm.reserve_pub"
diff --git a/src/exchangedb/pg_select_purse_requests_above_serial_id.c 
b/src/exchangedb/pg_select_purse_requests_above_serial_id.c
index 51f5de82..61a4f204 100644
--- a/src/exchangedb/pg_select_purse_requests_above_serial_id.c
+++ b/src/exchangedb/pg_select_purse_requests_above_serial_id.c
@@ -155,8 +155,7 @@ TEH_PG_select_purse_requests_above_serial_id (
            "SELECT"
            " purse_requests_serial_id"
            ",purse_pub"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
+           ",amount_with_fee"
            ",age_limit"
            ",h_contract_terms"
            ",purse_creation"
diff --git a/src/exchangedb/pg_select_recoup_above_serial_id.c 
b/src/exchangedb/pg_select_recoup_above_serial_id.c
index b2933fae..62e94f36 100644
--- a/src/exchangedb/pg_select_recoup_above_serial_id.c
+++ b/src/exchangedb/pg_select_recoup_above_serial_id.c
@@ -172,8 +172,7 @@ TEH_PG_select_recoup_above_serial_id (
            ",coins.denom_sig"
            ",coins.age_commitment_hash"
            ",denoms.denom_pub"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            " FROM recoup"
            "    JOIN known_coins coins"
            "      USING (coin_pub)"
diff --git a/src/exchangedb/pg_select_recoup_refresh_above_serial_id.c 
b/src/exchangedb/pg_select_recoup_refresh_above_serial_id.c
index c6fb62cc..b6029777 100644
--- a/src/exchangedb/pg_select_recoup_refresh_above_serial_id.c
+++ b/src/exchangedb/pg_select_recoup_refresh_above_serial_id.c
@@ -178,8 +178,7 @@ TEH_PG_select_recoup_refresh_above_serial_id (
            ",rrc.h_coin_ev AS h_blind_ev"
            ",new_denoms.denom_pub_hash"
            ",new_coins.denom_sig AS denom_sig"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            " FROM recoup_refresh"
            "    INNER JOIN refresh_revealed_coins rrc"
            "      USING (rrc_serial)"
diff --git a/src/exchangedb/pg_select_refreshes_above_serial_id.c 
b/src/exchangedb/pg_select_refreshes_above_serial_id.c
index 401e6dce..db432269 100644
--- a/src/exchangedb/pg_select_refreshes_above_serial_id.c
+++ b/src/exchangedb/pg_select_refreshes_above_serial_id.c
@@ -149,8 +149,7 @@ TEH_PG_select_refreshes_above_serial_id (
     .status = GNUNET_OK
   };
   enum GNUNET_DB_QueryStatus qs;
-  /* Used in #postgres_select_refreshes_above_serial_id() to fetch
-     refresh session with id '\geq' the given parameter */
+
   PREPARE (pg,
            "audit_get_refresh_commitments_incr",
            "SELECT"
@@ -158,8 +157,7 @@ TEH_PG_select_refreshes_above_serial_id (
            ",kc.coin_pub AS old_coin_pub"
            ",kc.age_commitment_hash"
            ",old_coin_sig"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
+           ",amount_with_fee"
            ",noreveal_index"
            ",melt_serial_id"
            ",rc"
diff --git a/src/exchangedb/pg_select_refunds_above_serial_id.c 
b/src/exchangedb/pg_select_refunds_above_serial_id.c
index d8c87d7d..34e6ba8b 100644
--- a/src/exchangedb/pg_select_refunds_above_serial_id.c
+++ b/src/exchangedb/pg_select_refunds_above_serial_id.c
@@ -188,8 +188,7 @@ TEH_PG_select_refunds_above_serial_id (
            ",ref.rtransaction_id"
            ",denom.denom_pub"
            ",kc.coin_pub"
-           ",ref.amount_with_fee_val"
-           ",ref.amount_with_fee_frac"
+           ",ref.amount_with_fee"
            ",ref.refund_serial_id"
            " FROM refunds ref"
            "   JOIN deposits dep"
@@ -203,16 +202,14 @@ TEH_PG_select_refunds_above_serial_id (
   PREPARE (pg,
            "test_refund_full",
            "SELECT"
-           " CAST(SUM(CAST(ref.amount_with_fee_frac AS INT8)) AS INT8) AS s_f"
-           ",CAST(SUM(ref.amount_with_fee_val) AS INT8) AS s_v"
-           ",dep.amount_with_fee_val"
-           ",dep.amount_with_fee_frac"
+           " CAST(SUM(CAST((ref.amount_with_fee).frac AS INT8)) AS INT8) AS 
s_f"
+           ",CAST(SUM((ref.amount_with_fee).val) AS INT8) AS s_v"
+           ",dep.amount_with_fee"
            " FROM refunds ref"
            "   JOIN deposits dep"
            "     ON (ref.coin_pub=dep.coin_pub AND 
ref.deposit_serial_id=dep.deposit_serial_id)"
            " WHERE ref.refund_serial_id=$1"
-           " GROUP BY (dep.amount_with_fee_val, dep.amount_with_fee_frac);");
-
+           " GROUP BY (dep.amount_with_fee);");
   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
                                              "audit_get_refunds_incr",
                                              params,
diff --git a/src/exchangedb/pg_select_refunds_by_coin.c 
b/src/exchangedb/pg_select_refunds_by_coin.c
index 7325b359..44a50579 100644
--- a/src/exchangedb/pg_select_refunds_by_coin.c
+++ b/src/exchangedb/pg_select_refunds_by_coin.c
@@ -153,8 +153,7 @@ TEH_PG_select_refunds_by_coin (
     PREPARE (pg,
              query,
              "SELECT"
-             " ref.amount_with_fee_val"
-             ",ref.amount_with_fee_frac"
+             " ref.amount_with_fee"
              " FROM refunds ref"
              " JOIN deposits dep"
              "   USING (coin_pub,deposit_serial_id)"
@@ -167,8 +166,7 @@ TEH_PG_select_refunds_by_coin (
     PREPARE (pg,
              query,
              "SELECT"
-             " ref.amount_with_fee_val"
-             ",ref.amount_with_fee_frac"
+             " ref.amount_with_fee"
              " FROM refunds ref"
              " LEFT JOIN deposits dep"
              "   ON dep.coin_pub = ref.coin_pub"
@@ -183,15 +181,13 @@ TEH_PG_select_refunds_by_coin (
              query,
              "WITH rc AS MATERIALIZED("
              "SELECT"
-             " amount_with_fee_val"
-             ",amount_with_fee_frac"
+             " amount_with_fee"
              ",coin_pub"
              ",deposit_serial_id"
              " FROM refunds ref"
              " WHERE ref.coin_pub=$1)"
              "SELECT"
-             "   rc.amount_with_fee_val"
-             "  ,rc.amount_with_fee_frac"
+             "   rc.amount_with_fee"
              "  FROM deposits dep"
              " JOIN rc"
              " ON rc.deposit_serial_id = dep.deposit_serial_id"
@@ -206,18 +202,15 @@ TEH_PG_select_refunds_by_coin (
              query,
              "WITH rc AS MATERIALIZED("
              "SELECT"
-             " amount_with_fee_val"
-             ",amount_with_fee_frac"
+             " amount_with_fee"
              ",deposit_serial_id"
              " FROM refunds"
              " WHERE coin_pub=$1)"
              "SELECT"
-             "   rc.amount_with_fee_val"
-             "  ,rc.amount_with_fee_frac"
+             "   rc.amount_with_fee"
              "  FROM ("
              "SELECT"
-             " amount_with_fee_val"
-             ",amount_with_fee_frac"
+             " amount_with_fee"
              " FROM deposits depos"
              "  WHERE"
              "  depos.coin_pub = $1"
@@ -230,20 +223,17 @@ TEH_PG_select_refunds_by_coin (
              query,
              "WITH rc AS MATERIALIZED("
              "SELECT"
-             " amount_with_fee_val"
-             ",amount_with_fee_frac"
+             " amount_with_fee"
              ",coin_pub"
              ",deposit_serial_id"
              " FROM refunds ref"
              " WHERE ref.coin_pub=$1)"
              "SELECT"
-             "   rc.amount_with_fee_val"
-             "  ,rc.amount_with_fee_frac"
+             "   rc.amount_with_fee"
              "  ,deposit_serial_id"
              "  FROM ("
              "SELECT"
-             " amount_with_fee_val"
-             ",amount_with_fee_frac"
+             " amount_with_fee"
              " FROM deposits depos"
              "  WHERE"
              "  depos.merchant_pub = $2"
@@ -256,8 +246,7 @@ TEH_PG_select_refunds_by_coin (
     PREPARE (pg,
              query,
              "SELECT"
-             " amount_with_fee_val"
-             ",amount_with_fee_frac"
+             " amount_with_fee"
              ",coin_pub"
              ",deposit_serial_id"
              " FROM refunds"
@@ -270,8 +259,7 @@ TEH_PG_select_refunds_by_coin (
              "WITH"
              " rc AS MATERIALIZED("
              "  SELECT"
-             "   amount_with_fee_val"
-             "  ,amount_with_fee_frac"
+             "   amount_with_fee"
              "  ,coin_pub"
              "  ,deposit_serial_id"
              "  FROM refunds"
@@ -285,8 +273,7 @@ TEH_PG_select_refunds_by_coin (
              "    AND h_contract_terms = $3"
              ")"
              "SELECT"
-             "   rc.amount_with_fee_val"
-             "  ,rc.amount_with_fee_frac"
+             "   rc.amount_with_fee"
              "  FROM "
              "  rc JOIN dep USING (deposit_serial_id);");
     break;
@@ -295,8 +282,7 @@ TEH_PG_select_refunds_by_coin (
     PREPARE (pg,
              query,
              "SELECT"
-             "   ref.amount_with_fee_val"
-             "  ,ref.amount_with_fee_frac"
+             "   ref.amount_with_fee"
              " FROM deposits dep"
              " JOIN refunds ref USING(deposit_serial_id)"
              " WHERE dep.coin_pub IN ("
@@ -315,7 +301,7 @@ TEH_PG_select_refunds_by_coin (
              " FROM"
              " exchange_do_refund_by_coin"
              " ($1, $2, $3) "
-             " AS (amount_with_fee_val INT8, amount_with_fee_frac INT4);");
+             " AS (amount_with_fee taler_amount);");
     break;
   default:
     GNUNET_break (0);
diff --git a/src/exchangedb/pg_select_reserve_closed_above_serial_id.c 
b/src/exchangedb/pg_select_reserve_closed_above_serial_id.c
index 985c6792..d24d6a60 100644
--- a/src/exchangedb/pg_select_reserve_closed_above_serial_id.c
+++ b/src/exchangedb/pg_select_reserve_closed_above_serial_id.c
@@ -157,10 +157,8 @@ TEH_PG_select_reserve_closed_above_serial_id (
     ",execution_date"
     ",wtid"
     ",payto_uri AS receiver_account"
-    ",amount_val"
-    ",amount_frac"
-    ",closing_fee_val"
-    ",closing_fee_frac"
+    ",amount"
+    ",closing_fee"
     ",close_request_row"
     " FROM reserves_close"
     "   JOIN wire_targets"
diff --git a/src/exchangedb/pg_select_reserve_open_above_serial_id.c 
b/src/exchangedb/pg_select_reserve_open_above_serial_id.c
index cc33bc48..1675e71a 100644
--- a/src/exchangedb/pg_select_reserve_open_above_serial_id.c
+++ b/src/exchangedb/pg_select_reserve_open_above_serial_id.c
@@ -152,8 +152,7 @@ TEH_PG_select_reserve_open_above_serial_id (
     ",request_timestamp"
     ",expiration_date"
     ",reserve_sig"
-    ",reserve_payment_val"
-    ",reserve_payment_frac"
+    ",reserve_payment"
     ",requested_purse_limit"
     " FROM reserves_open_requests"
     " WHERE open_request_uuid>=$1"
diff --git a/src/exchangedb/pg_select_reserves_in_above_serial_id.c 
b/src/exchangedb/pg_select_reserves_in_above_serial_id.c
index 8dd4a9ab..21033e80 100644
--- a/src/exchangedb/pg_select_reserves_in_above_serial_id.c
+++ b/src/exchangedb/pg_select_reserves_in_above_serial_id.c
@@ -137,15 +137,12 @@ TEH_PG_select_reserves_in_above_serial_id (
   };
   enum GNUNET_DB_QueryStatus qs;
 
-  /* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound
-     transactions for reserves with serial id '\geq' the given parameter */
   PREPARE (pg,
            "audit_reserves_in_get_transactions_incr",
            "SELECT"
            " reserves.reserve_pub"
            ",wire_reference"
-           ",credit_val"
-           ",credit_frac"
+           ",credit"
            ",execution_date"
            ",payto_uri AS sender_account_details"
            ",reserve_in_serial_id"
diff --git a/src/exchangedb/pg_select_reserves_in_above_serial_id_by_account.c 
b/src/exchangedb/pg_select_reserves_in_above_serial_id_by_account.c
index 809df191..daedb3f8 100644
--- a/src/exchangedb/pg_select_reserves_in_above_serial_id_by_account.c
+++ b/src/exchangedb/pg_select_reserves_in_above_serial_id_by_account.c
@@ -138,15 +138,12 @@ TEH_PG_select_reserves_in_above_serial_id_by_account (
   };
   enum GNUNET_DB_QueryStatus qs;
 
-  /* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound
-     transactions for reserves with serial id '\geq' the given parameter */
   PREPARE (pg,
            "audit_reserves_in_get_transactions_incr_by_account",
            "SELECT"
            " reserves.reserve_pub"
            ",wire_reference"
-           ",credit_val"
-           ",credit_frac"
+           ",credit"
            ",execution_date"
            ",payto_uri AS sender_account_details"
            ",reserve_in_serial_id"
@@ -157,7 +154,6 @@ TEH_PG_select_reserves_in_above_serial_id_by_account (
            "   ON (wire_source_h_payto = wire_target_h_payto)"
            " WHERE reserve_in_serial_id>=$1 AND exchange_account_section=$2"
            " ORDER BY reserve_in_serial_id;");
-
   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
                                              
"audit_reserves_in_get_transactions_incr_by_account",
                                              params,
diff --git a/src/exchangedb/pg_select_wire_out_above_serial_id.c 
b/src/exchangedb/pg_select_wire_out_above_serial_id.c
index a9615ac8..8668c429 100644
--- a/src/exchangedb/pg_select_wire_out_above_serial_id.c
+++ b/src/exchangedb/pg_select_wire_out_above_serial_id.c
@@ -140,8 +140,7 @@ TEH_PG_select_wire_out_above_serial_id (
            ",execution_date"
            ",wtid_raw"
            ",payto_uri"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            " FROM wire_out"
            "   JOIN wire_targets"
            "     USING (wire_target_h_payto)"
diff --git a/src/exchangedb/pg_select_wire_out_above_serial_id_by_account.c 
b/src/exchangedb/pg_select_wire_out_above_serial_id_by_account.c
index a6c3f073..3448c5a4 100644
--- a/src/exchangedb/pg_select_wire_out_above_serial_id_by_account.c
+++ b/src/exchangedb/pg_select_wire_out_above_serial_id_by_account.c
@@ -135,7 +135,6 @@ TEH_PG_select_wire_out_above_serial_id_by_account (
   };
   enum GNUNET_DB_QueryStatus qs;
 
-  /* Used in #postgres_select_wire_out_above_serial_id_by_account() */
   PREPARE (pg,
            "audit_get_wire_incr_by_account",
            "SELECT"
@@ -143,8 +142,7 @@ TEH_PG_select_wire_out_above_serial_id_by_account (
            ",execution_date"
            ",wtid_raw"
            ",payto_uri"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            " FROM wire_out"
            "   JOIN wire_targets"
            "     USING (wire_target_h_payto)"
diff --git a/src/exchangedb/pg_select_withdraw_amounts_for_kyc_check.c 
b/src/exchangedb/pg_select_withdraw_amounts_for_kyc_check.c
index 339fa3e2..8875e22c 100644
--- a/src/exchangedb/pg_select_withdraw_amounts_for_kyc_check.c
+++ b/src/exchangedb/pg_select_withdraw_amounts_for_kyc_check.c
@@ -131,13 +131,11 @@ TEH_PG_select_withdraw_amounts_for_kyc_check (
     .status = GNUNET_OK
   };
   enum GNUNET_DB_QueryStatus qs;
-  /* Used in #postgres_select_withdraw_amounts_for_kyc_check (
- () */
+
   PREPARE (pg,
            "select_kyc_relevant_withdraw_events",
            "SELECT"
-           " ro.amount_with_fee_val AS amount_val"
-           ",ro.amount_with_fee_frac AS amount_frac"
+           " ro.amount_with_fee AS amount"
            ",ro.execution_date AS date"
            " FROM reserves_out ro"
            " JOIN reserves_out_by_reserve USING (h_blind_ev)"
diff --git a/src/exchangedb/pg_select_withdrawals_above_serial_id.c 
b/src/exchangedb/pg_select_withdrawals_above_serial_id.c
index b842b11a..9beb0f93 100644
--- a/src/exchangedb/pg_select_withdrawals_above_serial_id.c
+++ b/src/exchangedb/pg_select_withdrawals_above_serial_id.c
@@ -142,7 +142,6 @@ TEH_PG_select_withdrawals_above_serial_id (
   enum GNUNET_DB_QueryStatus qs;
 
   /* Fetch deposits with rowid '\geq' the given parameter */
-
   PREPARE (pg,
            "audit_get_reserves_out_incr",
            "SELECT"
@@ -151,8 +150,7 @@ TEH_PG_select_withdrawals_above_serial_id (
            ",reserve_sig"
            ",reserves.reserve_pub"
            ",execution_date"
-           ",amount_with_fee_val"
-           ",amount_with_fee_frac"
+           ",amount_with_fee"
            ",reserve_out_serial_id"
            " FROM reserves_out"
            "    JOIN reserves"
@@ -161,8 +159,6 @@ TEH_PG_select_withdrawals_above_serial_id (
            "      USING (denominations_serial)"
            " WHERE reserve_out_serial_id>=$1"
            " ORDER BY reserve_out_serial_id ASC;");
-
-
   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
                                              "audit_get_reserves_out_incr",
                                              params,
diff --git a/src/exchangedb/pg_set_purse_balance.c 
b/src/exchangedb/pg_set_purse_balance.c
index e955cb1c..ef8673f9 100644
--- a/src/exchangedb/pg_set_purse_balance.c
+++ b/src/exchangedb/pg_set_purse_balance.c
@@ -35,15 +35,15 @@ TEH_PG_set_purse_balance (
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_auto_from_type (purse_pub),
-    TALER_PQ_query_param_amount (balance),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       balance),
     GNUNET_PQ_query_param_end
   };
 
   PREPARE (pg,
            "set_purse_balance",
            "UPDATE purse_requests"
-           " SET balance_val=$2"
-           "    ,balance_frac=$3"
+           " SET balance=$2"
            " WHERE purse_pub=$1;");
 
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
diff --git a/src/exchangedb/pg_store_wire_transfer_out.c 
b/src/exchangedb/pg_store_wire_transfer_out.c
index b8b0bb69..c899a487 100644
--- a/src/exchangedb/pg_store_wire_transfer_out.c
+++ b/src/exchangedb/pg_store_wire_transfer_out.c
@@ -40,11 +40,11 @@ TEH_PG_store_wire_transfer_out (
     GNUNET_PQ_query_param_auto_from_type (wtid),
     GNUNET_PQ_query_param_auto_from_type (h_payto),
     GNUNET_PQ_query_param_string (exchange_account_section),
-    TALER_PQ_query_param_amount (amount),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       amount),
     GNUNET_PQ_query_param_end
   };
 
-  /* Used in #postgres_store_wire_transfer_out */
   PREPARE (pg,
            "insert_wire_out",
            "INSERT INTO wire_out "
@@ -52,11 +52,9 @@ TEH_PG_store_wire_transfer_out (
            ",wtid_raw"
            ",wire_target_h_payto"
            ",exchange_account_section"
-           ",amount_val"
-           ",amount_frac"
+           ",amount"
            ") VALUES "
-           "($1, $2, $3, $4, $5, $6);");
-
+           "($1, $2, $3, $4, $5);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_wire_out",
                                              params);
diff --git a/src/exchangedb/pg_trigger_aml_process.c 
b/src/exchangedb/pg_trigger_aml_process.c
index 4dfc8a50..a46b4147 100644
--- a/src/exchangedb/pg_trigger_aml_process.c
+++ b/src/exchangedb/pg_trigger_aml_process.c
@@ -35,7 +35,8 @@ TEH_PG_trigger_aml_process (
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_auto_from_type (h_payto),
-    TALER_PQ_query_param_amount (threshold_crossed),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       threshold_crossed),
     GNUNET_PQ_query_param_end
   };
 
@@ -43,15 +44,13 @@ TEH_PG_trigger_aml_process (
            "trigger_aml_process",
            "INSERT INTO aml_status"
            "(h_payto"
-           ",threshold_val"
-           ",threshold_frac"
+           ",threshold"
            ",status)"
            "VALUES"
-           "($1, $2, $3, 1)" // 1: decision needed
+           "($1, $2, 1)" // 1: decision needed
            "ON CONFLICT DO"
            " UPDATE SET"
-           "   threshold_val=$2"
-           "  ,threshold_frac=$3"
+           "   threshold=$2"
            "  ,status=status | 1;"); // do not clear 'frozen' status
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "trigger_aml_process",
diff --git a/src/exchangedb/pg_update_aggregation_transient.c 
b/src/exchangedb/pg_update_aggregation_transient.c
index c44cd67e..06c76882 100644
--- a/src/exchangedb/pg_update_aggregation_transient.c
+++ b/src/exchangedb/pg_update_aggregation_transient.c
@@ -36,23 +36,21 @@ TEH_PG_update_aggregation_transient (
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
-    TALER_PQ_query_param_amount (total),
+    TALER_PQ_query_param_amount_tuple (pg->conn,
+                                       total),
     GNUNET_PQ_query_param_auto_from_type (h_payto),
     GNUNET_PQ_query_param_auto_from_type (wtid),
     GNUNET_PQ_query_param_uint64 (&kyc_requirement_row),
     GNUNET_PQ_query_param_end
   };
 
-
-  /* Used in #postgres_update_aggregation_transient() */
   PREPARE (pg,
            "update_aggregation_transient",
            "UPDATE aggregation_transient"
-           " SET amount_val=$1"
-           "    ,amount_frac=$2"
-           "    ,legitimization_requirement_serial_id=$5"
-           " WHERE wire_target_h_payto=$3"
-           "   AND wtid_raw=$4");
+           " SET amount=$1"
+           "    ,legitimization_requirement_serial_id=$4"
+           " WHERE wire_target_h_payto=$2"
+           "   AND wtid_raw=$3");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "update_aggregation_transient",
                                              params);
diff --git a/src/exchangedb/shard-0001.sql b/src/exchangedb/shard-0001.sql
deleted file mode 100644
index 03066443..00000000
--- a/src/exchangedb/shard-0001.sql
+++ /dev/null
@@ -1,2575 +0,0 @@
-BEGIN;
-SELECT _v.register_patch('shard-0001', NULL, NULL);
-CREATE SCHEMA exchange;
-COMMENT ON SCHEMA exchange IS 'taler-exchange data';
-SET search_path TO exchange;
-CREATE OR REPLACE FUNCTION create_partitioned_table(
-   IN table_definition VARCHAR
-  ,IN table_name VARCHAR
-  ,IN main_table_partition_str VARCHAR 
-  ,IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  IF shard_suffix IS NOT NULL THEN
-    table_name=table_name || '_' || shard_suffix;
-    main_table_partition_str = '';
-  END IF;
-  EXECUTE FORMAT(
-    table_definition,
-    table_name,
-    main_table_partition_str
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_wire_targets(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(wire_target_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',wire_target_h_payto BYTEA PRIMARY KEY CHECK 
(LENGTH(wire_target_h_payto)=32)'
-      ',payto_uri VARCHAR NOT NULL'
-    ') %s ;'
-    ,'wire_targets'
-    ,'PARTITION BY HASH (wire_target_h_payto)'
-    ,shard_suffix
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_wire_targets_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE wire_targets_' || partition_suffix || ' '
-      'ADD CONSTRAINT wire_targets_' || partition_suffix || 
'_wire_target_serial_id_key '
-        'UNIQUE (wire_target_serial_id)'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_legitimization_processes(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(legitimization_process_serial_id BIGINT GENERATED BY DEFAULT AS 
IDENTITY' 
-      ',h_payto BYTEA NOT NULL CHECK (LENGTH(h_payto)=32)'
-      ',expiration_time INT8 NOT NULL DEFAULT (0)'
-      ',provider_section VARCHAR NOT NULL'
-      ',provider_user_id VARCHAR DEFAULT NULL'
-      ',provider_legitimization_id VARCHAR DEFAULT NULL'
-      ',UNIQUE (h_payto, provider_section)'
-    ') %s ;'
-    ,'legitimization_processes'
-    ,'PARTITION BY HASH (h_payto)'
-    ,shard_suffix
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION 
add_constraints_to_legitimization_processes_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  partition_name VARCHAR;
-BEGIN
-  partition_name = concat_ws('_', 'legitimization_processes', 
partition_suffix);
-  EXECUTE FORMAT (
-    'ALTER TABLE ' || partition_name
-    || ' '
-      'ADD CONSTRAINT ' || partition_name || '_serial_key '
-        'UNIQUE (legitimization_process_serial_id)');
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || partition_name || 
'_by_provider_and_legi_index '
-        'ON '|| partition_name || ' '
-        '(provider_section,provider_legitimization_id)'
-  );
-  EXECUTE FORMAT (
-    'COMMENT ON INDEX ' || partition_name || '_by_provider_and_legi_index '
-    'IS ' || quote_literal('used (rarely) in kyc_provider_account_lookup') || 
';'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_legitimization_requirements(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(legitimization_requirement_serial_id BIGINT GENERATED BY DEFAULT AS 
IDENTITY' 
-      ',h_payto BYTEA NOT NULL CHECK (LENGTH(h_payto)=32)'
-      ',required_checks VARCHAR NOT NULL'
-      ',UNIQUE (h_payto, required_checks)'
-    ') %s ;'
-    ,'legitimization_requirements'
-    ,'PARTITION BY HASH (h_payto)'
-    ,shard_suffix
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION 
add_constraints_to_legitimization_requirements_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  partition_name VARCHAR;
-BEGIN
-  partition_name = concat_ws('_', 'legitimization_requirements', 
partition_suffix);
-  EXECUTE FORMAT (
-    'ALTER TABLE ' || partition_name
-    || ' '
-      'ADD CONSTRAINT ' || partition_name || '_serial_id_key '
-        'UNIQUE (legitimization_requirement_serial_id)');
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_reserves(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'reserves';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(reserve_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY'
-      ',reserve_pub BYTEA PRIMARY KEY CHECK(LENGTH(reserve_pub)=32)'
-      ',current_balance_val INT8 NOT NULL DEFAULT(0)'
-      ',current_balance_frac INT4 NOT NULL DEFAULT(0)'
-      ',purses_active INT8 NOT NULL DEFAULT(0)'
-      ',purses_allowed INT8 NOT NULL DEFAULT(0)'
-      ',birthdate INT4 NOT NULL DEFAULT(0)' -- 0 means: no age restriction.
-      ',expiration_date INT8 NOT NULL'
-      ',gc_date INT8 NOT NULL'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (reserve_pub)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_expiration_index '
-    'ON ' || table_name || ' '
-    '(expiration_date'
-    ',current_balance_val'
-    ',current_balance_frac'
-    ');'
-  );
-  EXECUTE FORMAT (
-    'COMMENT ON INDEX ' || table_name || '_by_expiration_index '
-    'IS ' || quote_literal('used in get_expired_reserves') || ';'
-  );
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_uuid_index '
-    'ON ' || table_name || ' '
-    '(reserve_uuid);'
-  );
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_gc_date_index '
-    'ON ' || table_name || ' '
-    '(gc_date);'
-  );
-  EXECUTE FORMAT (
-    'COMMENT ON INDEX ' || table_name || '_by_gc_date_index '
-    'IS ' || quote_literal('for reserve garbage collection') || ';'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_reserves_in(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR default 'reserves_in';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(reserve_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',reserve_pub BYTEA PRIMARY KEY' 
-      ',wire_reference INT8 NOT NULL'
-      ',credit_val INT8 NOT NULL'
-      ',credit_frac INT4 NOT NULL'
-      ',wire_source_h_payto BYTEA CHECK (LENGTH(wire_source_h_payto)=32)'
-      ',exchange_account_section TEXT NOT NULL'
-      ',execution_date INT8 NOT NULL'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (reserve_pub)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || 
'_by_reserve_in_serial_id_index '
-    'ON ' || table_name || ' '
-    '(reserve_in_serial_id);'
-  );
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || 
'_by_exch_accnt_section_execution_date_idx '
-    'ON ' || table_name || ' '
-    '(exchange_account_section '
-    ',execution_date'
-    ');'
-  );
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || 
'_by_exch_accnt_reserve_in_serial_id_idx '
-    'ON ' || table_name || ' '
-    '(exchange_account_section,'
-    'reserve_in_serial_id DESC'
-    ');'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_reserves_in_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE reserves_in_' || partition_suffix || ' '
-      'ADD CONSTRAINT reserves_in_' || partition_suffix || 
'_reserve_in_serial_id_key '
-        'UNIQUE (reserve_in_serial_id)'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_reserves_close(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR default 'reserves_close';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(close_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',reserve_pub BYTEA NOT NULL' 
-      ',execution_date INT8 NOT NULL'
-      ',wtid BYTEA NOT NULL CHECK (LENGTH(wtid)=32)'
-      ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
-      ',amount_val INT8 NOT NULL'
-      ',amount_frac INT4 NOT NULL'
-      ',closing_fee_val INT8 NOT NULL'
-      ',closing_fee_frac INT4 NOT NULL'
-      ',close_request_row INT8 NOT NULL DEFAULT(0)'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (reserve_pub)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_close_uuid_index '
-    'ON ' || table_name || ' '
-    '(close_uuid);'
-  );
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_pub_index '
-    'ON ' || table_name || ' '
-    '(reserve_pub);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_reserves_close_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE reserves_close_' || partition_suffix || ' '
-      'ADD CONSTRAINT reserves_close_' || partition_suffix || 
'_close_uuid_pkey '
-        'PRIMARY KEY (close_uuid)'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_close_requests(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'close_requests';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I '
-      '(close_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)' 
-      ',close_timestamp INT8 NOT NULL'
-      ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
-      ',close_val INT8 NOT NULL'
-      ',close_frac INT4 NOT NULL'
-      ',close_fee_val INT8 NOT NULL'
-      ',close_fee_frac INT4 NOT NULL'
-      ',payto_uri VARCHAR NOT NULL'
-      ',done BOOL NOT NULL DEFAULT(FALSE)'
-      ',PRIMARY KEY (reserve_pub,close_timestamp)'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (reserve_pub)'
-    ,shard_suffix
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_close_requests(
-  IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'close_requests';
-BEGIN
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || 
'_by_close_request_uuid_index '
-    'ON ' || table_name || ' '
-    '(close_request_serial_id);'
-  );
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || 
'_by_close_request_done_index '
-    'ON ' || table_name || ' '
-    '(done);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_close_requests_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE close_requests_' || partition_suffix || ' '
-      'ADD CONSTRAINT close_requests_' || partition_suffix || 
'_close_request_uuid_pkey '
-        'UNIQUE (close_request_serial_id)'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_reserves_open_requests(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR default 'reserves_open_requests';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(open_request_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',reserve_pub BYTEA NOT NULL' 
-      ',request_timestamp INT8 NOT NULL'
-      ',expiration_date INT8 NOT NULL'
-      ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
-      ',reserve_payment_val INT8 NOT NULL'
-      ',reserve_payment_frac INT4 NOT NULL'
-      ',requested_purse_limit INT4 NOT NULL'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (reserve_pub)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || 
'_by_reserve_open_uuid_index '
-    'ON ' || table_name || ' '
-    '(open_request_uuid);'
-  );
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_pub_index '
-    'ON ' || table_name || ' '
-    '(reserve_pub);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_reserves_open_request_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE reserves_open_requests_' || partition_suffix || ' '
-      'ADD CONSTRAINT reserves_open_requests_' || partition_suffix || 
'_by_uuid '
-        'PRIMARY KEY (open_request_uuid),'
-      'ADD CONSTRAINT reserves_open_requests_' || partition_suffix || 
'_by_time '
-        'UNIQUE (reserve_pub,request_timestamp)'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_reserves_open_deposits(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR default 'reserves_open_deposits';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(reserve_open_deposit_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
-      ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)'
-      ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
-      ',coin_sig BYTEA NOT NULL CHECK (LENGTH(coin_sig)=64)'
-      ',contribution_val INT8 NOT NULL'
-      ',contribution_frac INT4 NOT NULL'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (coin_pub)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_uuid '
-    'ON ' || table_name || ' '
-    '(reserve_open_deposit_uuid);'
-  );
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve '
-    'ON ' || table_name || ' '
-    '(reserve_pub);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_reserves_open_deposits_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE reserves_open_deposits_' || partition_suffix || ' '
-      'ADD CONSTRAINT reserves_open_deposits_' || partition_suffix || 
'_coin_unique '
-        'PRIMARY KEY (coin_pub,coin_sig)'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_reserves_out(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR default 'reserves_out';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(reserve_out_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',h_blind_ev BYTEA CHECK (LENGTH(h_blind_ev)=64) UNIQUE'
-      ',denominations_serial INT8 NOT NULL' 
-      ',denom_sig BYTEA NOT NULL'
-      ',reserve_uuid INT8 NOT NULL' 
-      ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
-      ',execution_date INT8 NOT NULL'
-      ',amount_with_fee_val INT8 NOT NULL'
-      ',amount_with_fee_frac INT4 NOT NULL'
-    ') %s ;'
-    ,'reserves_out'
-    ,'PARTITION BY HASH (h_blind_ev)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || 
'_by_reserve_out_serial_id_index '
-    'ON ' || table_name || ' '
-    '(reserve_out_serial_id);'
-  );
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || 
'_by_reserve_uuid_and_execution_date_index '
-    'ON ' || table_name || ' '
-    '(reserve_uuid, execution_date);'
-  );
-  EXECUTE FORMAT (
-    'COMMENT ON INDEX ' || table_name || 
'_by_reserve_uuid_and_execution_date_index '
-    'IS ' || quote_literal('for get_reserves_out and 
exchange_do_withdraw_limit_check') || ';'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_reserves_out_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE reserves_out_' || partition_suffix || ' '
-      'ADD CONSTRAINT reserves_out_' || partition_suffix || 
'_reserve_out_serial_id_key '
-        'UNIQUE (reserve_out_serial_id)'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_reserves_out_by_reserve(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'reserves_out_by_reserve';
-BEGIN
-  PERFORM create_partitioned_table(
-  'CREATE TABLE IF NOT EXISTS %I'
-    '(reserve_uuid INT8 NOT NULL' 
-    ',h_blind_ev BYTEA CHECK (LENGTH(h_blind_ev)=64)'
-    ') %s '
-    ,table_name
-    ,'PARTITION BY HASH (reserve_uuid)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_main_index '
-    'ON ' || table_name || ' '
-    '(reserve_uuid);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_known_coins(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR default 'known_coins';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(known_coin_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',denominations_serial INT8 NOT NULL' 
-      ',coin_pub BYTEA NOT NULL PRIMARY KEY CHECK (LENGTH(coin_pub)=32)'
-      ',age_commitment_hash BYTEA CHECK (LENGTH(age_commitment_hash)=32)'
-      ',denom_sig BYTEA NOT NULL'
-      ',remaining_val INT8 NOT NULL DEFAULT(0)'
-      ',remaining_frac INT4 NOT NULL DEFAULT(0)'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (coin_pub)' 
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_known_coins_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE known_coins_' || partition_suffix || ' '
-      'ADD CONSTRAINT known_coins_' || partition_suffix || '_known_coin_id_key 
'
-        'UNIQUE (known_coin_id)'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_refresh_commitments(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'refresh_commitments';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(melt_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',rc BYTEA PRIMARY KEY CHECK (LENGTH(rc)=64)'
-      ',old_coin_pub BYTEA NOT NULL' 
-      ',old_coin_sig BYTEA NOT NULL CHECK(LENGTH(old_coin_sig)=64)'
-      ',amount_with_fee_val INT8 NOT NULL'
-      ',amount_with_fee_frac INT4 NOT NULL'
-      ',noreveal_index INT4 NOT NULL'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (rc)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_old_coin_pub_index '
-    'ON ' || table_name || ' '
-    '(old_coin_pub);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_refresh_commitments_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE refresh_commitments_' || partition_suffix || ' '
-      'ADD CONSTRAINT refresh_commitments_' || partition_suffix || 
'_melt_serial_id_key '
-        'UNIQUE (melt_serial_id)'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_refresh_revealed_coins(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'refresh_revealed_coins';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(rrc_serial BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',melt_serial_id INT8 NOT NULL' 
-      ',freshcoin_index INT4 NOT NULL'
-      ',link_sig BYTEA NOT NULL CHECK(LENGTH(link_sig)=64)'
-      ',denominations_serial INT8 NOT NULL' 
-      ',coin_ev BYTEA NOT NULL' 
-      ',h_coin_ev BYTEA NOT NULL CHECK(LENGTH(h_coin_ev)=64)' 
-      ',ev_sig BYTEA NOT NULL'
-      ',ewv BYTEA NOT NULL'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (melt_serial_id)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || 
'_coins_by_melt_serial_id_index '
-    'ON ' || table_name || ' '
-    '(melt_serial_id);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_refresh_revealed_coins_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE refresh_revealed_coins_' || partition_suffix || ' '
-      'ADD CONSTRAINT refresh_revealed_coins_' || partition_suffix || 
'_rrc_serial_key '
-        'UNIQUE (rrc_serial) '
-      ',ADD CONSTRAINT refresh_revealed_coins_' || partition_suffix || 
'_coin_ev_key '
-        'UNIQUE (coin_ev) '
-      ',ADD CONSTRAINT refresh_revealed_coins_' || partition_suffix || 
'_h_coin_ev_key '
-        'UNIQUE (h_coin_ev) '
-      ',ADD PRIMARY KEY (melt_serial_id, freshcoin_index) '
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_refresh_transfer_keys(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'refresh_transfer_keys';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(rtc_serial BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',melt_serial_id INT8 PRIMARY KEY' 
-      ',transfer_pub BYTEA NOT NULL CHECK(LENGTH(transfer_pub)=32)'
-      ',transfer_privs BYTEA NOT NULL'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (melt_serial_id)'
-    ,shard_suffix
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_refresh_transfer_keys_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE refresh_transfer_keys_' || partition_suffix || ' '
-      'ADD CONSTRAINT refresh_transfer_keys_' || partition_suffix || 
'_rtc_serial_key '
-        'UNIQUE (rtc_serial)'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_deposits(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'deposits';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(deposit_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',shard INT8 NOT NULL'
-      ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' 
-      ',known_coin_id INT8 NOT NULL' 
-      ',amount_with_fee_val INT8 NOT NULL'
-      ',amount_with_fee_frac INT4 NOT NULL'
-      ',wallet_timestamp INT8 NOT NULL'
-      ',exchange_timestamp INT8 NOT NULL'
-      ',refund_deadline INT8 NOT NULL'
-      ',wire_deadline INT8 NOT NULL'
-      ',merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)'
-      ',h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)'
-      ',coin_sig BYTEA NOT NULL CHECK (LENGTH(coin_sig)=64)'
-      ',wire_salt BYTEA NOT NULL CHECK (LENGTH(wire_salt)=16)'
-      ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
-      ',done BOOLEAN NOT NULL DEFAULT FALSE'
-      ',policy_blocked BOOLEAN NOT NULL DEFAULT FALSE'
-      ',policy_details_serial_id INT8' 
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (coin_pub)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub_index '
-    'ON ' || table_name || ' '
-    '(coin_pub);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_deposits_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE deposits_' || partition_suffix || ' '
-      'ADD CONSTRAINT deposits_' || partition_suffix || 
'_deposit_serial_id_pkey '
-        'PRIMARY KEY (deposit_serial_id) '
-      ',ADD CONSTRAINT deposits_' || partition_suffix || 
'_coin_pub_merchant_pub_h_contract_terms_key '
-        'UNIQUE (coin_pub, merchant_pub, h_contract_terms)'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_deposits_by_ready(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'deposits_by_ready';
-BEGIN
-  PERFORM create_partitioned_table(
-  'CREATE TABLE IF NOT EXISTS %I'
-    '(wire_deadline INT8 NOT NULL'
-    ',shard INT8 NOT NULL'
-    ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
-    ',deposit_serial_id INT8'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY RANGE (wire_deadline)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_main_index '
-    'ON ' || table_name || ' '
-    '(wire_deadline ASC, shard ASC, coin_pub);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_deposits_for_matching(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'deposits_for_matching';
-BEGIN
-  PERFORM create_partitioned_table(
-  'CREATE TABLE IF NOT EXISTS %I'
-    '(refund_deadline INT8 NOT NULL'
-    ',merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)'
-    ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' 
-    ',deposit_serial_id INT8'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY RANGE (refund_deadline)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_main_index '
-    'ON ' || table_name || ' '
-    '(refund_deadline ASC, merchant_pub, coin_pub);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_refunds(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'refunds';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(refund_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' 
-      ',deposit_serial_id INT8 NOT NULL' 
-      ',merchant_sig BYTEA NOT NULL CHECK(LENGTH(merchant_sig)=64)'
-      ',rtransaction_id INT8 NOT NULL'
-      ',amount_with_fee_val INT8 NOT NULL'
-      ',amount_with_fee_frac INT4 NOT NULL'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (coin_pub)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub_index '
-    'ON ' || table_name || ' '
-    '(coin_pub);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_refunds_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE refunds_' || partition_suffix || ' '
-      'ADD CONSTRAINT refunds_' || partition_suffix || '_refund_serial_id_key '
-        'UNIQUE (refund_serial_id) '
-      ',ADD PRIMARY KEY (deposit_serial_id, rtransaction_id) '
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_wire_out(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'wire_out';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(wireout_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',execution_date INT8 NOT NULL'
-      ',wtid_raw BYTEA UNIQUE NOT NULL CHECK (LENGTH(wtid_raw)=32)'
-      ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
-      ',exchange_account_section TEXT NOT NULL'
-      ',amount_val INT8 NOT NULL'
-      ',amount_frac INT4 NOT NULL'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (wtid_raw)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || 
'_by_wire_target_h_payto_index '
-    'ON ' || table_name || ' '
-    '(wire_target_h_payto);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_wire_out_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE wire_out_' || partition_suffix || ' '
-      'ADD CONSTRAINT wire_out_' || partition_suffix || '_wireout_uuid_pkey '
-        'PRIMARY KEY (wireout_uuid)'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_aggregation_transient(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'aggregation_transient';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I '
-      '(amount_val INT8 NOT NULL'
-      ',amount_frac INT4 NOT NULL'
-      ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
-      ',merchant_pub BYTEA CHECK (LENGTH(merchant_pub)=32)'
-      ',exchange_account_section TEXT NOT NULL'
-      ',legitimization_requirement_serial_id INT8 NOT NULL DEFAULT(0)'
-      ',wtid_raw BYTEA NOT NULL CHECK (LENGTH(wtid_raw)=32)'
-      ') %s ;'
-      ,table_name
-      ,'PARTITION BY HASH (wire_target_h_payto)'
-      ,shard_suffix
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_aggregation_tracking(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'aggregation_tracking';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(aggregation_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-     ',deposit_serial_id INT8 PRIMARY KEY' 
-      ',wtid_raw BYTEA NOT NULL' 
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (deposit_serial_id)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_wtid_raw_index '
-    'ON ' || table_name || ' '
-    '(wtid_raw);'
-  );
-  EXECUTE FORMAT (
-    'COMMENT ON INDEX ' || table_name || '_by_wtid_raw_index '
-    'IS ' || quote_literal('for lookup_transactions') || ';'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_aggregation_tracking_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE aggregation_tracking_' || partition_suffix || ' '
-      'ADD CONSTRAINT aggregation_tracking_' || partition_suffix || 
'_aggregation_serial_id_key '
-        'UNIQUE (aggregation_serial_id) '
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_recoup(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'recoup';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(recoup_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' 
-      ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
-      ',coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)'
-      ',amount_val INT8 NOT NULL'
-      ',amount_frac INT4 NOT NULL'
-      ',recoup_timestamp INT8 NOT NULL'
-      ',reserve_out_serial_id INT8 NOT NULL' 
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (coin_pub);'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub_index '
-    'ON ' || table_name || ' '
-    '(coin_pub);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_recoup_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE recoup_' || partition_suffix || ' '
-      'ADD CONSTRAINT recoup_' || partition_suffix || '_recoup_uuid_key '
-        'UNIQUE (recoup_uuid) '
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_recoup_by_reserve(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'recoup_by_reserve';
-BEGIN
-  PERFORM create_partitioned_table(
-  'CREATE TABLE IF NOT EXISTS %I'
-    '(reserve_out_serial_id INT8 NOT NULL' 
-    ',coin_pub BYTEA CHECK (LENGTH(coin_pub)=32)' 
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (reserve_out_serial_id)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_main_index '
-    'ON ' || table_name || ' '
-    '(reserve_out_serial_id);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_recoup_refresh(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'recoup_refresh';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(recoup_refresh_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' 
-      ',known_coin_id BIGINT NOT NULL' 
-      ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
-      ',coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)'
-      ',amount_val INT8 NOT NULL'
-      ',amount_frac INT4 NOT NULL'
-      ',recoup_timestamp INT8 NOT NULL'
-      ',rrc_serial INT8 NOT NULL' 
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (coin_pub)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_rrc_serial_index '
-    'ON ' || table_name || ' '
-    '(rrc_serial);'
-  );
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub_index '
-    'ON ' || table_name || ' '
-    '(coin_pub);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_recoup_refresh_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE recoup_refresh_' || partition_suffix || ' '
-      'ADD CONSTRAINT recoup_refresh_' || partition_suffix || 
'_recoup_refresh_uuid_key '
-        'UNIQUE (recoup_refresh_uuid) '
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_prewire(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'prewire';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(prewire_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY'
-      ',wire_method TEXT NOT NULL'
-      ',finished BOOLEAN NOT NULL DEFAULT false'
-      ',failed BOOLEAN NOT NULL DEFAULT false'
-      ',buf BYTEA NOT NULL'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (prewire_uuid)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_finished_index '
-    'ON ' || table_name || ' '
-    '(finished);'
-  );
-  EXECUTE FORMAT (
-    'COMMENT ON INDEX ' || table_name || '_by_finished_index '
-    'IS ' || quote_literal('for gc_prewire') || ';'
-  );
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_failed_finished_index '
-    'ON ' || table_name || ' '
-    '(failed,finished);'
-  );
-  EXECUTE FORMAT (
-    'COMMENT ON INDEX ' || table_name || '_by_failed_finished_index '
-    'IS ' || quote_literal('for wire_prepare_data_get') || ';'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_cs_nonce_locks(
-  shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I'
-      '(cs_nonce_lock_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',nonce BYTEA PRIMARY KEY CHECK (LENGTH(nonce)=32)'
-      ',op_hash BYTEA NOT NULL CHECK (LENGTH(op_hash)=64)'
-      ',max_denomination_serial INT8 NOT NULL'
-    ') %s ;'
-    ,'cs_nonce_locks'
-    ,'PARTITION BY HASH (nonce)'
-    ,shard_suffix
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_cs_nonce_locks_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE cs_nonce_locks_' || partition_suffix || ' '
-      'ADD CONSTRAINT cs_nonce_locks_' || partition_suffix || 
'_cs_nonce_lock_serial_id_key '
-        'UNIQUE (cs_nonce_lock_serial_id)'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_purse_requests(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'purse_requests';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I '
-      '(purse_requests_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
-      ',merge_pub BYTEA NOT NULL CHECK (LENGTH(merge_pub)=32)'
-      ',purse_creation INT8 NOT NULL'
-      ',purse_expiration INT8 NOT NULL'
-      ',h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)'
-      ',age_limit INT4 NOT NULL'
-      ',flags INT4 NOT NULL'
-      ',in_reserve_quota BOOLEAN NOT NULL DEFAULT(FALSE)'
-      ',amount_with_fee_val INT8 NOT NULL'
-      ',amount_with_fee_frac INT4 NOT NULL'
-      ',purse_fee_val INT8 NOT NULL'
-      ',purse_fee_frac INT4 NOT NULL'
-      ',balance_val INT8 NOT NULL DEFAULT (0)'
-      ',balance_frac INT4 NOT NULL DEFAULT (0)'
-      ',purse_sig BYTEA NOT NULL CHECK(LENGTH(purse_sig)=64)'
-      ',PRIMARY KEY (purse_pub)'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (purse_pub)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_merge_pub '
-    'ON ' || table_name || ' '
-    '(merge_pub);'
-  );
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_purse_expiration '
-    'ON ' || table_name || ' '
-    '(purse_expiration);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_purse_requests_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE purse_requests_' || partition_suffix || ' '
-      'ADD CONSTRAINT purse_requests_' || partition_suffix || 
'_purse_requests_serial_id_key '
-        'UNIQUE (purse_requests_serial_id) '
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_purse_merges(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'purse_merges';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I '
-      '(purse_merge_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY '
-      ',partner_serial_id INT8' 
-      ',reserve_pub BYTEA NOT NULL CHECK(length(reserve_pub)=32)'
-      ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)' 
-      ',merge_sig BYTEA NOT NULL CHECK (LENGTH(merge_sig)=64)'
-      ',merge_timestamp INT8 NOT NULL'
-      ',PRIMARY KEY (purse_pub)'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (purse_pub)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_reserve_pub '
-    'ON ' || table_name || ' '
-    '(reserve_pub);'
-  );
-  EXECUTE FORMAT (
-    'COMMENT ON INDEX ' || table_name || '_reserve_pub '
-    'IS ' || quote_literal('needed in reserve history computation') || ';'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_purse_merges_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE purse_merges_' || partition_suffix || ' '
-      'ADD CONSTRAINT purse_merges_' || partition_suffix || 
'_purse_merge_request_serial_id_key '
-        'UNIQUE (purse_merge_request_serial_id) '
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_account_merges(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'account_merges';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I '
-      '(account_merge_request_serial_id BIGINT GENERATED BY DEFAULT AS 
IDENTITY' 
-      ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)' 
-      ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
-      ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)' 
-      ',wallet_h_payto BYTEA NOT NULL CHECK (LENGTH(wallet_h_payto)=32)'
-      ',PRIMARY KEY (purse_pub)'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (purse_pub)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_pub '
-    'ON ' || table_name || ' '
-    '(reserve_pub);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_account_merges_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE account_merges_' || partition_suffix || ' '
-      'ADD CONSTRAINT account_merges_' || partition_suffix || 
'_account_merge_request_serial_id_key '
-        'UNIQUE (account_merge_request_serial_id) '
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_purse_decision(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'purse_decision';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I '
-      '(purse_decision_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
-      ',action_timestamp INT8 NOT NULL'
-      ',refunded BOOL NOT NULL'
-      ',PRIMARY KEY (purse_pub)'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (purse_pub)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_purse_decision_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE purse_decision_' || partition_suffix || ' '
-      'ADD CONSTRAINT purse_decision_' || partition_suffix || 
'_purse_action_serial_id_key '
-        'UNIQUE (purse_decision_serial_id) '
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_contracts(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'contracts';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I '
-      '(contract_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
-      ',pub_ckey BYTEA NOT NULL CHECK (LENGTH(pub_ckey)=32)'
-      ',contract_sig BYTEA NOT NULL CHECK (LENGTH(contract_sig)=64)'
-      ',e_contract BYTEA NOT NULL'
-      ',purse_expiration INT8 NOT NULL'
-      ',PRIMARY KEY (purse_pub)'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (purse_pub)'
-    ,shard_suffix
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_contracts_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE contracts_' || partition_suffix || ' '
-      'ADD CONSTRAINT contracts_' || partition_suffix || 
'_contract_serial_id_key '
-        'UNIQUE (contract_serial_id) '
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_history_requests(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'history_requests';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I '
-      '(history_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)' 
-      ',request_timestamp INT8 NOT NULL'
-      ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
-      ',history_fee_val INT8 NOT NULL'
-      ',history_fee_frac INT4 NOT NULL'
-      ',PRIMARY KEY (reserve_pub,request_timestamp)'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (reserve_pub)'
-    ,shard_suffix
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_purse_deposits(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'purse_deposits';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I '
-      '(purse_deposit_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',partner_serial_id INT8' 
-      ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
-      ',coin_pub BYTEA NOT NULL' 
-      ',amount_with_fee_val INT8 NOT NULL'
-      ',amount_with_fee_frac INT4 NOT NULL'
-      ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
-      ',PRIMARY KEY (purse_pub,coin_pub)'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (purse_pub)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub '
-    'ON ' || table_name || ' '
-    '(coin_pub);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_purse_deposits_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE purse_deposits_' || partition_suffix || ' '
-      'ADD CONSTRAINT purse_deposits_' || partition_suffix || 
'_purse_deposit_serial_id_key '
-        'UNIQUE (purse_deposit_serial_id) '
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_wads_out(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'wads_out';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I '
-      '(wad_out_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',wad_id BYTEA PRIMARY KEY CHECK (LENGTH(wad_id)=24)'
-      ',partner_serial_id INT8 NOT NULL' 
-      ',amount_val INT8 NOT NULL'
-      ',amount_frac INT4 NOT NULL'
-      ',execution_time INT8 NOT NULL'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (wad_id)'
-    ,shard_suffix
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_wads_out_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE wads_out_' || partition_suffix || ' '
-      'ADD CONSTRAINT wads_out_' || partition_suffix || 
'_wad_out_serial_id_key '
-        'UNIQUE (wad_out_serial_id) '
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_wad_out_entries(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'wad_out_entries';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I '
-      '(wad_out_entry_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',wad_out_serial_id INT8' 
-      ',reserve_pub BYTEA NOT NULL CHECK(LENGTH(reserve_pub)=32)'
-      ',purse_pub BYTEA PRIMARY KEY CHECK(LENGTH(purse_pub)=32)'
-      ',h_contract BYTEA NOT NULL CHECK(LENGTH(h_contract)=64)'
-      ',purse_expiration INT8 NOT NULL'
-      ',merge_timestamp INT8 NOT NULL'
-      ',amount_with_fee_val INT8 NOT NULL'
-      ',amount_with_fee_frac INT4 NOT NULL'
-      ',wad_fee_val INT8 NOT NULL'
-      ',wad_fee_frac INT4 NOT NULL'
-      ',deposit_fees_val INT8 NOT NULL'
-      ',deposit_fees_frac INT4 NOT NULL'
-      ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
-      ',purse_sig BYTEA NOT NULL CHECK (LENGTH(purse_sig)=64)'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (purse_pub)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_pub '
-    'ON ' || table_name || ' '
-    '(reserve_pub);'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_wad_out_entries_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE wad_out_entries_' || partition_suffix || ' '
-      'ADD CONSTRAINT wad_out_entries_' || partition_suffix || 
'_wad_out_entry_serial_id_key '
-        'UNIQUE (wad_out_entry_serial_id) '
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_wads_in(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'wads_in';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I '
-      '(wad_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',wad_id BYTEA PRIMARY KEY CHECK (LENGTH(wad_id)=24)'
-      ',origin_exchange_url TEXT NOT NULL'
-      ',amount_val INT8 NOT NULL'
-      ',amount_frac INT4 NOT NULL'
-      ',arrival_time INT8 NOT NULL'
-      ',UNIQUE (wad_id, origin_exchange_url)'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (wad_id)'
-    ,shard_suffix
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_wads_in_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE wads_in_' || partition_suffix || ' '
-      'ADD CONSTRAINT wads_in_' || partition_suffix || '_wad_in_serial_id_key '
-        'UNIQUE (wad_in_serial_id) '
-      ',ADD CONSTRAINT wads_in_' || partition_suffix || 
'_wad_is_origin_exchange_url_key '
-        'UNIQUE (wad_id, origin_exchange_url) '
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_table_wad_in_entries(
-  IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  table_name VARCHAR DEFAULT 'wad_in_entries';
-BEGIN
-  PERFORM create_partitioned_table(
-    'CREATE TABLE IF NOT EXISTS %I '
-      '(wad_in_entry_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' 
-      ',wad_in_serial_id INT8' 
-      ',reserve_pub BYTEA NOT NULL CHECK(LENGTH(reserve_pub)=32)'
-      ',purse_pub BYTEA PRIMARY KEY CHECK(LENGTH(purse_pub)=32)'
-      ',h_contract BYTEA NOT NULL CHECK(LENGTH(h_contract)=64)'
-      ',purse_expiration INT8 NOT NULL'
-      ',merge_timestamp INT8 NOT NULL'
-      ',amount_with_fee_val INT8 NOT NULL'
-      ',amount_with_fee_frac INT4 NOT NULL'
-      ',wad_fee_val INT8 NOT NULL'
-      ',wad_fee_frac INT4 NOT NULL'
-      ',deposit_fees_val INT8 NOT NULL'
-      ',deposit_fees_frac INT4 NOT NULL'
-      ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
-      ',purse_sig BYTEA NOT NULL CHECK (LENGTH(purse_sig)=64)'
-    ') %s ;'
-    ,table_name
-    ,'PARTITION BY HASH (purse_pub)'
-    ,shard_suffix
-  );
-  table_name = concat_ws('_', table_name, shard_suffix);
-  EXECUTE FORMAT (
-    'CREATE INDEX IF NOT EXISTS ' || table_name || '_reserve_pub '
-    'ON ' || table_name || ' '
-    '(reserve_pub);'
-  );
-  EXECUTE FORMAT (
-    'COMMENT ON INDEX ' || table_name || '_reserve_pub '
-    'IS ' || quote_literal('needed in reserve history computation') || ';'
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION add_constraints_to_wad_in_entries_partition(
-  IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  EXECUTE FORMAT (
-    'ALTER TABLE wad_in_entries_' || partition_suffix || ' '
-      'ADD CONSTRAINT wad_in_entries_' || partition_suffix || 
'_wad_in_entry_serial_id_key '
-        'UNIQUE (wad_in_entry_serial_id) '
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_hash_partition(
-    source_table_name VARCHAR
-    ,modulus INTEGER
-    ,partition_num INTEGER
-  )
-  RETURNS VOID
-  LANGUAGE plpgsql
-AS $$
-BEGIN
-  RAISE NOTICE 'Creating partition %_%', source_table_name, partition_num;
-  EXECUTE FORMAT(
-    'CREATE TABLE IF NOT EXISTS %I '
-      'PARTITION OF %I '
-      'FOR VALUES WITH (MODULUS %s, REMAINDER %s)'
-    ,source_table_name || '_' || partition_num
-    ,source_table_name
-    ,modulus
-    ,partition_num-1
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_range_partition(
-  source_table_name VARCHAR
-  ,partition_num INTEGER
-)
-  RETURNS void
-  LANGUAGE plpgsql
-AS $$
-BEGIN
-  RAISE NOTICE 'TODO';
-END
-$$;
-CREATE OR REPLACE FUNCTION detach_default_partitions()
-  RETURNS VOID
-  LANGUAGE plpgsql
-AS $$
-BEGIN
-  RAISE NOTICE 'Detaching all default table partitions';
-  ALTER TABLE IF EXISTS wire_targets
-    DETACH PARTITION wire_targets_default;
-  ALTER TABLE IF EXISTS reserves
-    DETACH PARTITION reserves_default;
-  ALTER TABLE IF EXISTS reserves_in
-    DETACH PARTITION reserves_in_default;
-  ALTER TABLE IF EXISTS reserves_close
-    DETACH PARTITION reserves_close_default;
-  ALTER TABLE IF EXISTS history_requests
-    DETACH partition history_requests_default;
-  ALTER TABLE IF EXISTS close_requests
-    DETACH partition close_requests_default;
-  ALTER TABLE IF EXISTS reserves_open_requests
-    DETACH partition reserves_open_requests_default;
-  ALTER TABLE IF EXISTS reserves_out
-    DETACH PARTITION reserves_out_default;
-  ALTER TABLE IF EXISTS reserves_out_by_reserve
-    DETACH PARTITION reserves_out_by_reserve_default;
-  ALTER TABLE IF EXISTS known_coins
-    DETACH PARTITION known_coins_default;
-  ALTER TABLE IF EXISTS refresh_commitments
-    DETACH PARTITION refresh_commitments_default;
-  ALTER TABLE IF EXISTS refresh_revealed_coins
-    DETACH PARTITION refresh_revealed_coins_default;
-  ALTER TABLE IF EXISTS refresh_transfer_keys
-    DETACH PARTITION refresh_transfer_keys_default;
-  ALTER TABLE IF EXISTS deposits
-    DETACH PARTITION deposits_default;
-  ALTER TABLE IF EXISTS refunds
-    DETACH PARTITION refunds_default;
-  ALTER TABLE IF EXISTS wire_out
-    DETACH PARTITION wire_out_default;
-  ALTER TABLE IF EXISTS aggregation_transient
-    DETACH PARTITION aggregation_transient_default;
-  ALTER TABLE IF EXISTS aggregation_tracking
-    DETACH PARTITION aggregation_tracking_default;
-  ALTER TABLE IF EXISTS recoup
-    DETACH PARTITION recoup_default;
-  ALTER TABLE IF EXISTS recoup_by_reserve
-    DETACH PARTITION recoup_by_reserve_default;
-  ALTER TABLE IF EXISTS recoup_refresh
-    DETACH PARTITION recoup_refresh_default;
-  ALTER TABLE IF EXISTS prewire
-    DETACH PARTITION prewire_default;
-  ALTER TABLE IF EXISTS cs_nonce_locks
-    DETACH partition cs_nonce_locks_default;
-  ALTER TABLE IF EXISTS purse_requests
-    DETACH partition purse_requests_default;
-  ALTER TABLE IF EXISTS purse_decision
-    DETACH partition purse_decision_default;
-  ALTER TABLE IF EXISTS purse_merges
-    DETACH partition purse_merges_default;
-  ALTER TABLE IF EXISTS account_merges
-    DETACH partition account_merges_default;
-  ALTER TABLE IF EXISTS contracts
-    DETACH partition contracts_default;
-  ALTER TABLE IF EXISTS purse_deposits
-    DETACH partition purse_deposits_default;
-  ALTER TABLE IF EXISTS wad_out_entries
-    DETACH partition wad_out_entries_default;
-  ALTER TABLE IF EXISTS wads_in
-    DETACH partition wads_in_default;
-  ALTER TABLE IF EXISTS wad_in_entries
-    DETACH partition wad_in_entries_default;
-END
-$$;
-COMMENT ON FUNCTION detach_default_partitions
-  IS 'We need to drop default and create new one before deleting the default 
partitions
-      otherwise constraints get lost too. Might be needed in sharding too';
-CREATE OR REPLACE FUNCTION drop_default_partitions()
-  RETURNS VOID
-  LANGUAGE plpgsql
-AS $$
-BEGIN
-  RAISE NOTICE 'Dropping default table partitions';
-  DROP TABLE IF EXISTS wire_targets_default;
-  DROP TABLE IF EXISTS reserves_default;
-  DROP TABLE IF EXISTS reserves_in_default;
-  DROP TABLE IF EXISTS reserves_close_default;
-  DROP TABLE IF EXISTS reserves_open_requests_default;
-  DROP TABLE IF EXISTS history_requests_default;
-  DROP TABLE IF EXISTS close_requests_default;
-  DROP TABLE IF EXISTS reserves_out_default;
-  DROP TABLE IF EXISTS reserves_out_by_reserve_default;
-  DROP TABLE IF EXISTS known_coins_default;
-  DROP TABLE IF EXISTS refresh_commitments_default;
-  DROP TABLE IF EXISTS refresh_revealed_coins_default;
-  DROP TABLE IF EXISTS refresh_transfer_keys_default;
-  DROP TABLE IF EXISTS deposits_default;
-  DROP TABLE IF EXISTS refunds_default;
-  DROP TABLE IF EXISTS wire_out_default;
-  DROP TABLE IF EXISTS aggregation_transient_default;
-  DROP TABLE IF EXISTS aggregation_tracking_default;
-  DROP TABLE IF EXISTS recoup_default;
-  DROP TABLE IF EXISTS recoup_by_reserve_default;
-  DROP TABLE IF EXISTS recoup_refresh_default;
-  DROP TABLE IF EXISTS prewire_default;
-  DROP TABLE IF EXISTS cs_nonce_locks_default;
-  DROP TABLE IF EXISTS purse_requests_default;
-  DROP TABLE IF EXISTS purse_decision_default;
-  DROP TABLE IF EXISTS purse_merges_default;
-  DROP TABLE IF EXISTS account_merges_default;
-  DROP TABLE IF EXISTS purse_deposits_default;
-  DROP TABLE IF EXISTS contracts_default;
-  DROP TABLE IF EXISTS wad_out_entries_default;
-  DROP TABLE IF EXISTS wads_in_default;
-  DROP TABLE IF EXISTS wad_in_entries_default;
-END
-$$;
-COMMENT ON FUNCTION drop_default_partitions
-  IS 'Drop all default partitions once other partitions are attached.
-      Might be needed in sharding too.';
-CREATE OR REPLACE FUNCTION create_partitions(
-    num_partitions INTEGER
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  modulus INTEGER;
-BEGIN
-  modulus := num_partitions;
-  PERFORM detach_default_partitions();
-  LOOP
-    PERFORM create_hash_partition(
-      'wire_targets'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM add_constraints_to_wire_targets_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'reserves'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM create_hash_partition(
-      'reserves_in'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM add_constraints_to_reserves_in_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'reserves_close'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM 
add_constraints_to_reserves_close_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'reserves_out'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM add_constraints_to_reserves_out_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'reserves_out_by_reserve'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM create_hash_partition(
-      'known_coins'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM add_constraints_to_known_coins_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'refresh_commitments'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM 
add_constraints_to_refresh_commitments_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'refresh_revealed_coins'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM 
add_constraints_to_refresh_revealed_coins_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'refresh_transfer_keys'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM 
add_constraints_to_refresh_transfer_keys_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'deposits'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM add_constraints_to_deposits_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'refunds'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM add_constraints_to_refunds_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'wire_out'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM add_constraints_to_wire_out_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'aggregation_transient'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM create_hash_partition(
-      'aggregation_tracking'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM 
add_constraints_to_aggregation_tracking_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'recoup'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM add_constraints_to_recoup_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'recoup_by_reserve'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM create_hash_partition(
-      'recoup_refresh'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM 
add_constraints_to_recoup_refresh_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'prewire'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM create_hash_partition(
-      'cs_nonce_locks'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM 
add_constraints_to_cs_nonce_locks_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'close_requests'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM create_hash_partition(
-      'reserves_open_requests'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM 
add_constraints_to_reserves_open_request_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'history_requests'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM create_hash_partition(
-      'purse_requests'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM 
add_constraints_to_purse_requests_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'purse_decision'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM 
add_constraints_to_purse_decision_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'purse_merges'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM add_constraints_to_purse_merges_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'account_merges'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM 
add_constraints_to_account_merges_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'contracts'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM add_constraints_to_contracts_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'purse_deposits'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM 
add_constraints_to_purse_deposits_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'wad_out_entries'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM 
add_constraints_to_wad_out_entries_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'wads_in'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM add_constraints_to_wads_in_partition(num_partitions::varchar);
-    PERFORM create_hash_partition(
-      'wad_in_entries'
-      ,modulus
-      ,num_partitions
-    );
-    PERFORM 
add_constraints_to_wad_in_entries_partition(num_partitions::varchar);
-    num_partitions=num_partitions-1;
-    EXIT WHEN num_partitions=0;
-  END LOOP;
-  PERFORM drop_default_partitions();
-END
-$$;
-CREATE OR REPLACE FUNCTION create_foreign_hash_partition(
-    source_table_name VARCHAR
-    ,modulus INTEGER
-    ,shard_suffix VARCHAR
-    ,current_shard_num INTEGER
-    ,local_user VARCHAR DEFAULT 'taler-exchange-httpd'
-  )
-  RETURNS VOID
-  LANGUAGE plpgsql
-AS $$
-BEGIN
-  RAISE NOTICE 'Creating %_% on %', source_table_name, shard_suffix, 
shard_suffix;
-  EXECUTE FORMAT(
-    'CREATE FOREIGN TABLE IF NOT EXISTS %I '
-      'PARTITION OF %I '
-      'FOR VALUES WITH (MODULUS %s, REMAINDER %s) '
-      'SERVER %I'
-    ,source_table_name || '_' || shard_suffix
-    ,source_table_name
-    ,modulus
-    ,current_shard_num-1
-    ,shard_suffix
-  );
-  EXECUTE FORMAT(
-    'ALTER FOREIGN TABLE %I OWNER TO %I'
-    ,source_table_name || '_' || shard_suffix
-    ,local_user
-  );
-END
-$$;
-CREATE OR REPLACE FUNCTION create_foreign_range_partition(
-  source_table_name VARCHAR
-  ,partition_num INTEGER
-)
-  RETURNS VOID
-  LANGUAGE plpgsql
-AS $$
-BEGIN
-   RAISE NOTICE 'TODO';
-END
-$$;
-CREATE OR REPLACE FUNCTION prepare_sharding()
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  CREATE EXTENSION IF NOT EXISTS postgres_fdw;
-  PERFORM detach_default_partitions();
-  ALTER TABLE IF EXISTS wire_targets
-    DROP CONSTRAINT IF EXISTS wire_targets_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS reserves
-    DROP CONSTRAINT IF EXISTS reserves_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS reserves_in
-    DROP CONSTRAINT IF EXISTS reserves_in_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS reserves_close
-    DROP CONSTRAINT IF EXISTS reserves_close_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS reserves_out
-    DROP CONSTRAINT IF EXISTS reserves_out_pkey CASCADE
-    ,DROP CONSTRAINT IF EXISTS reserves_out_denominations_serial_fkey
-    ,DROP CONSTRAINT IF EXISTS reserves_out_h_blind_ev_key
-  ;
-  ALTER TABLE IF EXISTS known_coins
-    DROP CONSTRAINT IF EXISTS known_coins_pkey CASCADE
-    ,DROP CONSTRAINT IF EXISTS known_coins_denominations_serial_fkey
-  ;
-  ALTER TABLE IF EXISTS refresh_commitments
-    DROP CONSTRAINT IF EXISTS refresh_commitments_pkey CASCADE
-    ,DROP CONSTRAINT IF EXISTS refresh_old_coin_pub_fkey
-  ;
-  ALTER TABLE IF EXISTS refresh_revealed_coins
-    DROP CONSTRAINT IF EXISTS refresh_revealed_coins_pkey CASCADE
-    ,DROP CONSTRAINT IF EXISTS refresh_revealed_coins_denominations_serial_fkey
-  ;
-  ALTER TABLE IF EXISTS refresh_transfer_keys
-    DROP CONSTRAINT IF EXISTS refresh_transfer_keys_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS deposits
-    DROP CONSTRAINT IF EXISTS deposits_pkey CASCADE
-    ,DROP CONSTRAINT IF EXISTS deposits_policy_details_serial_id_fkey
-    ,DROP CONSTRAINT IF EXISTS 
deposits_coin_pub_merchant_pub_h_contract_terms_key CASCADE
-  ;
-  ALTER TABLE IF EXISTS refunds
-    DROP CONSTRAINT IF EXISTS refunds_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS wire_out
-    DROP CONSTRAINT IF EXISTS wire_out_pkey CASCADE
-    ,DROP CONSTRAINT IF EXISTS wire_out_wtid_raw_key CASCADE
-  ;
-  ALTER TABLE IF EXISTS aggregation_tracking
-    DROP CONSTRAINT IF EXISTS aggregation_tracking_pkey CASCADE
-    ,DROP CONSTRAINT IF EXISTS aggregation_tracking_wtid_raw_fkey
-  ;
-  ALTER TABLE IF EXISTS recoup
-    DROP CONSTRAINT IF EXISTS recoup_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS recoup_refresh
-    DROP CONSTRAINT IF EXISTS recoup_refresh_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS prewire
-    DROP CONSTRAINT IF EXISTS prewire_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS cs_nonce_locks
-    DROP CONSTRAINT IF EXISTS cs_nonce_locks_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS purse_requests
-    DROP CONSTRAINT IF EXISTS purse_requests_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS purse_decision
-    DROP CONSTRAINT IF EXISTS purse_decision_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS purse_merges
-    DROP CONSTRAINT IF EXISTS purse_merges_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS account_merges
-    DROP CONSTRAINT IF EXISTS account_merges_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS contracts
-    DROP CONSTRAINT IF EXISTS contracts_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS history_requests
-    DROP CONSTRAINT IF EXISTS history_requests_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS close_requests
-    DROP CONSTRAINT IF EXISTS close_requests_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS purse_deposits
-    DROP CONSTRAINT IF EXISTS purse_deposits_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS wads_out
-    DROP CONSTRAINT IF EXISTS wads_out_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS wad_out_entries
-    DROP CONSTRAINT IF EXISTS wad_out_entries_pkey CASCADE
-  ;
-  ALTER TABLE IF EXISTS wads_in
-    DROP CONSTRAINT IF EXISTS wads_in_pkey CASCADE
-    ,DROP CONSTRAINT IF EXISTS wads_in_wad_id_origin_exchange_url_key
-  ;
-  ALTER TABLE IF EXISTS wad_in_entries
-    DROP CONSTRAINT IF EXISTS wad_in_entries_pkey CASCADE
-  ;
-END
-$$;
-CREATE OR REPLACE FUNCTION create_shard_server(
-    shard_suffix VARCHAR
-    ,total_num_shards INTEGER
-    ,current_shard_num INTEGER
-    ,remote_host VARCHAR
-    ,remote_user VARCHAR
-    ,remote_user_password VARCHAR
-    ,remote_db_name VARCHAR DEFAULT 'taler-exchange'
-    ,remote_port INTEGER DEFAULT '5432'
-    ,local_user VARCHAR DEFAULT 'taler-exchange-httpd'
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-  RAISE NOTICE 'Creating server %', remote_host;
-  EXECUTE FORMAT(
-    'CREATE SERVER IF NOT EXISTS %I '
-      'FOREIGN DATA WRAPPER postgres_fdw '
-      'OPTIONS (dbname %L, host %L, port %L)'
-    ,shard_suffix
-    ,remote_db_name
-    ,remote_host
-    ,remote_port
-  );
-  EXECUTE FORMAT(
-    'CREATE USER MAPPING IF NOT EXISTS '
-      'FOR %I SERVER %I '
-      'OPTIONS (user %L, password %L)'
-    ,local_user
-    ,shard_suffix
-    ,remote_user
-    ,remote_user_password
-  );
-  EXECUTE FORMAT(
-    'GRANT ALL PRIVILEGES '
-      'ON FOREIGN SERVER %I '
-      'TO %I;'
-    ,shard_suffix
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'wire_targets'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'reserves'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'reserves_in'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'reserves_out'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'reserves_out_by_reserve'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'reserves_close'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'history_requests'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'close_requests'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'open_requests'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'known_coins'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'refresh_commitments'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'refresh_revealed_coins'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'refresh_transfer_keys'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'deposits'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'refunds'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'wire_out'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'aggregation_transient'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'aggregation_tracking'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'recoup'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'recoup_by_reserve'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'recoup_refresh'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'prewire'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'cs_nonce_locks'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'purse_requests'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'purse_decision'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'purse_merges'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'account_merges'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'contracts'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'purse_deposits'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'wad_out_entries'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'wads_in'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-  PERFORM create_foreign_hash_partition(
-    'wad_in_entries'
-    ,total_num_shards
-    ,shard_suffix
-    ,current_shard_num
-    ,local_user
-  );
-END
-$$;
-COMMENT ON FUNCTION create_shard_server
-  IS 'Create a shard server on the master
-      node with all foreign tables and user mappings';
-CREATE OR REPLACE FUNCTION create_foreign_servers(
-  amount INTEGER
-  ,domain VARCHAR
-  ,remote_user VARCHAR DEFAULT 'taler'
-  ,remote_user_password VARCHAR DEFAULT 'taler'
-)
-  RETURNS VOID
-  LANGUAGE plpgsql
-AS $$
-BEGIN
-  PERFORM prepare_sharding();
-  FOR i IN 1..amount LOOP
-    PERFORM create_shard_server(
-      i::varchar
-     ,amount
-     ,i
-     ,'shard-' || i::varchar || '.' || domain
-     ,remote_user
-     ,remote_user_password
-     ,'taler-exchange'
-     ,'5432'
-     ,'taler-exchange-httpd'
-    );
-  END LOOP;
-  PERFORM drop_default_partitions();
-END
-$$;
-CREATE OR REPLACE FUNCTION setup_shard(
-  shard_idx INTEGER
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  shard_suffix VARCHAR;
-BEGIN
-  shard_suffix = shard_idx::varchar;
-  PERFORM create_table_wire_targets(shard_suffix);
-  PERFORM add_constraints_to_wire_targets_partition(shard_suffix);
-  PERFORM create_table_reserves(shard_suffix);
-  PERFORM create_table_legitimization_requirements(shard_suffix);
-  PERFORM 
add_constraints_to_legitimization_requirements_partition(shard_suffix);
-  PERFORM create_table_legitimization_processes(shard_suffix);
-  PERFORM add_constraints_to_legitimization_processes_partition(shard_suffix);
-  PERFORM create_table_reserves_in(shard_suffix);
-  PERFORM add_constraints_to_reserves_in_partition(shard_suffix);
-  PERFORM create_table_reserves_close(shard_suffix);
-  PERFORM add_constraints_to_reserves_close_partition(shard_suffix);
-  PERFORM create_table_reserves_open_requests(shard_suffix);
-  PERFORM add_constraints_to_reserves_open_request_partition(shard_suffix);
-  PERFORM create_table_reserves_open_deposits(shard_suffix);
-  PERFORM add_constraints_to_reserves_open_deposits_partition(shard_suffix);
-  PERFORM create_table_reserves_out(shard_suffix);
-  PERFORM add_constraints_to_reserves_out_partition(shard_suffix);
-  PERFORM create_table_reserves_out_by_reserve(shard_suffix);
-  PERFORM create_table_known_coins(shard_suffix);
-  PERFORM add_constraints_to_known_coins_partition(shard_suffix);
-  PERFORM create_table_refresh_commitments(shard_suffix);
-  PERFORM add_constraints_to_refresh_commitments_partition(shard_suffix);
-  PERFORM create_table_refresh_revealed_coins(shard_suffix);
-  PERFORM add_constraints_to_refresh_revealed_coins_partition(shard_suffix);
-  PERFORM create_table_refresh_transfer_keys(shard_suffix);
-  PERFORM add_constraints_to_refresh_transfer_keys_partition(shard_suffix);
-  PERFORM create_table_deposits(shard_suffix);
-  PERFORM add_constraints_to_deposits_partition(shard_suffix);
-  PERFORM create_table_deposits_by_ready(shard_suffix);
-  PERFORM create_table_deposits_for_matching(shard_suffix);
-  PERFORM create_table_refunds(shard_suffix);
-  PERFORM add_constraints_to_refunds_partition(shard_suffix);
-  PERFORM create_table_wire_out(shard_suffix);
-  PERFORM add_constraints_to_wire_out_partition(shard_suffix);
-  PERFORM create_table_aggregation_transient(shard_suffix);
-  PERFORM create_table_aggregation_tracking(shard_suffix);
-  PERFORM add_constraints_to_aggregation_tracking_partition(shard_suffix);
-  PERFORM create_table_recoup(shard_suffix);
-  PERFORM add_constraints_to_recoup_partition(shard_suffix);
-  PERFORM create_table_recoup_by_reserve(shard_suffix);
-  PERFORM create_table_recoup_refresh(shard_suffix);
-  PERFORM add_constraints_to_recoup_refresh_partition(shard_suffix);
-  PERFORM create_table_prewire(shard_suffix);
-  PERFORM create_table_cs_nonce_locks(shard_suffix);
-  PERFORM add_constraints_to_cs_nonce_locks_partition(shard_suffix);
-  PERFORM create_table_purse_requests(shard_suffix);
-  PERFORM add_constraints_to_purse_requests_partition(shard_suffix);
-  PERFORM create_table_purse_decision(shard_suffix);
-  PERFORM add_constraints_to_purse_decision_partition(shard_suffix);
-  PERFORM create_table_purse_merges(shard_suffix);
-  PERFORM add_constraints_to_purse_merges_partition(shard_suffix);
-  PERFORM create_table_account_merges(shard_suffix);
-  PERFORM add_constraints_to_account_merges_partition(shard_suffix);
-  PERFORM create_table_contracts(shard_suffix);
-  PERFORM add_constraints_to_contracts_partition(shard_suffix);
-  PERFORM create_table_history_requests(shard_suffix);
-  PERFORM create_table_close_requests(shard_suffix);
-  PERFORM add_constraints_to_close_requests_partition(shard_suffix);
-  PERFORM create_table_purse_deposits(shard_suffix);
-  PERFORM add_constraints_to_purse_deposits_partition(shard_suffix);
-  PERFORM create_table_wad_out_entries(shard_suffix);
-  PERFORM add_constraints_to_wad_out_entries_partition(shard_suffix);
-  PERFORM create_table_wads_in(shard_suffix);
-  PERFORM add_constraints_to_wads_in_partition(shard_suffix);
-  PERFORM create_table_wad_in_entries(shard_suffix);
-  PERFORM add_constraints_to_wad_in_entries_partition(shard_suffix);
-END
-$$;
-COMMIT;

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]