postgresql trx calculation