开发者社区 > PolarDB开源 > PolarDB 分布式版 > 正文

对了几遍好像和你这个差别不大,但是执行就报错了,说return query这个语法有问题。 dro

对了几遍好像和你这个差别不大,但是执行就报错了,说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;

展开
收起
绿子直子 2023-04-25 19:14:27 302 0
2 条回答
写回答
取消 提交回答
  • 要在函数计算中执行 SQL 函数,建议使用 MySQL 的语法。以下是一个示例,您可以参考以下代码来创建类似的 MySQL 函数:

    drop function if exists hermes_reward_user; create function hermes_reward_user(block_height FLOAT) returns table(block_height FLOAT, action_hash text, amount FLOAT, recipient text, type text) as begin return 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 > block_height 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 > block_height 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 > block_height; end; 做出改动后,您可以尝试重新上传该函数,并在函数计算中进行测试

    2023-04-26 08:53:01
    赞同 展开评论 打赏
  • 改成language plpgsql;

    此答案来自钉钉群“PG|POLARDB技术进阶"

    2023-04-25 19:52:31
    赞同 展开评论 打赏

PolarDB 分布式版 (PolarDB for Xscale,简称“PolarDB-X”) 是阿里云自主设计研发的高性能云原生分布式数据库产品,为用户提供高吞吐、大存储、低延时、易扩展和超高可用的云时代数据库服务。

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载