小编Den*_*kov的帖子

Postgres:如何获取枚举集中的下一个项目?

考虑使用下面的代码.类型enum_buysell仅包含2个值:buysell.在某些情况下我需要得到相反的值,但代码看起来很难看,imho.有没有办法优化它?我认为根本不使用枚举,例如将其设为布尔值,但这个想法并不完美,因为它使数据本身不那么明显.

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,
  volume
from
  deals
where
  account_id_active  = p_account_id or
  account_id_passive = p_account_id
order by
  datetime desc
limit
  10;
Run Code Online (Sandbox Code Playgroud)

postgresql enums

6
推荐指数
1
解决办法
156
查看次数

标签 统计

enums ×1

postgresql ×1