tags:

views:

15

answers:

1

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
  )
A: 

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
  )

xycf7
Yes - that was the issue.
Fakrudeen