select datetime,case when account_ID_active = p_account_ID and direction = 'buy' then 'buy'::enum_buysell when account_ID_active = p_account_ID and direction = 'sell' then 'sell'::enum_buysell when account_ID_passive = p_account_ID and direction = 'buy' then 'sell'::enum_buysell when account_ID_passive = p_account_ID and direction = 'sell' then 'buy'::enum_buysell end as direction,price,volumefrom dealswhere account_ID_active = p_account_ID or account_ID_passive = p_account_IDorder by datetime desclimit 10;由于在Postgresql中没有获取枚举的下一个值的功能,您应该自己定义它.
create function next_buysell (e enum_buysell)returns enum_buysellas $$begin return (case when e='buy'::enum_buysell then 'sell'::enum_buysell else 'buy'::enum_buysell end);end$$language plpgsql;
现在,您可以像这样使用它:
postgres=# select next_buysell('sell'::enum_buysell); next_buysell-------------- buy(1 row)postgres=# select next_buysell('buy'::enum_buysell); next_buysell-------------- sell(1 row)
并且您的CASE声明变为:
case when account_ID_active = p_account_ID then direction when account_ID_passive = p_account_ID then next_buysell(direction)end as direction总结
以上是内存溢出为你收集整理的postgresql – Postgres:如何获取枚举集中的下一项?全部内容,希望文章能够帮你解决postgresql – Postgres:如何获取枚举集中的下一项?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)