对了几遍好像和你这个差别不大,但是执行就报错了,说return query这个语法有问题。
drop FUNCTION hermes_reward_user; create or replace function hermes_reward_user(block_height NUMERIC) returns table (block_height NUMERIC, action_hash text, amount NUMERIC, recipient text, type text) as $$ begin return query select block_height, act_hash as action_hash, amount, owner_address as recipient, ‘bucket’ as type from staking_actions WHERE sender in (‘io12mgttmfa2ffn9uqvn0yn37f4nz43d248l2ga85’, ‘io1lhukp867ume3qn2g7cxn4e47pj0ugfxeqj7nm8’, ‘io1h49cfw0zcj63chk6awu08u6xem8kpr350r5p57’, ‘io1unvkgm98ma3r2fnfrhep24arjxf6kc8stx0nuc’) and act_type = ‘DepositToStake’ and block_height > $1 union all select block_height, action_hash, amount, recipient, ‘transfer’ as type from block_action where sender in (‘io12mgttmfa2ffn9uqvn0yn37f4nz43d248l2ga85′,’io1lhukp867ume3qn2g7cxn4e47pj0ugfxeqj7nm8’) and action_type = ‘transfer’ and block_height > $1
union all
select block_height, action_hash, amount, recipient, 'transfer' as type from block_receipt_transactions where sender = 'io16y9wk2xnwurvtgmd2mds2gcdfe2lmzad6dcw29' and type = 'execution' and block_height > $1 ;
end;
$$ language sql;
改成language plpgsql;
此答案来自钉钉群“PG|POLARDB技术进阶”