开发者

passing a scalar query result to coalesce

How can I pass the result from a scalar [single row, single value] query to coalesce? I am trying to pick the priority as (the biggest priority so 开发者_运维技巧far in the table) + 1. [0 if it is the first row.]

create trigger priority_SuperRuleSamples before insert on SuperRuleSamples 
FOR EACH ROW 
  SET NEW.Priority=coalesce(NEW.Priority, 
   coalesce(
   select Priority from SuperRuleSamples order by Priority desc limit 1, 
   -1
   )+1
  )


it seems there is a parenthesis issue in your query. Can you try this?


create trigger priority_SuperRuleSamples before insert on SuperRuleSamples 
FOR EACH ROW 
  SET NEW.Priority=coalesce(NEW.Priority, 
   coalesce(
    (select Priority from SuperRuleSamples order by Priority desc limit 1), 
   -1
   )+1
  )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜