I want to list the all the field Names (Column Names) in the rowtype variable in postgres. Is there are anyways to accomplish it.
create or replace function purchase_payment_merchant_count() returns void as $$
DECLARE
currentrow operational.tbl_purchase_payments%rowtype;
BEGIN
RAISE WARNING 'Trigger Function Called';
raise WARNING 'Count %',(select count(*) as Counts from (select sum(pending_amount) as pending_amount, fk_merchant as fk_merchant
from operational.tbl_purchase_payments where fk_payment_status = 2 group by fk_merchant) counts);
FOR currentrow IN
select sum(pending_amount), fk_merchant
from operational.tbl_purchase_payments where fk_payment_status = 2 group by fk_merchant
loop
RAISE WARNING 'Current ROw %', currentrow;
RAISE WARNING 'Pending Amount: % and fk_merchant: %',currentrow.pending_amount,currentrow.fk_merchant;
update operational.tbl_merchant_accounts_payable
set pending_payment = currentrow.pending_amount
where fk_merchant = currentrow.fk_merchant;
END LOOP;
END;
$$ LANGUAGE plpgsql;
Logs:
2021-01-10 16:08:10.294 IST [2325] WARNING: Current ROw (3404,1,,,,,)
2021-01-10 16:08:10.294 IST [2325] CONTEXT: PL/pgSQL function purchase_payment_merchant_count() line 15 at RAISE
SQL statement "SELECT purchase_payment_merchant_count()"
PL/pgSQL function purchase_payment_merchant_metric() line 4 at PERFORM
2021-01-10 16:08:10.295 IST [2325] WARNING: Pending Amount: <NULL> and fk_merchant: <NULL>
Output from sql work bench:
| sum | fk_merchant |
|---|---|
| 3404.25 | 1 |