You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CREATE DEFINER=`bcadmin`@`%` TRIGGER `host_id_constraint` BEFORE INSERT ON `host` FOR EACH ROW begin
declare next_id int;
declare max_id int;
declare error_msg varchar(100);
set max_id = power(2, 9)-1;
set next_id = null;
select min(st.value) into next_id
from SEQUENCE_TABLE(max_id+1) st
left join host h on h.id=st.value
where st.value > 0
and h.id is null;
if isnull(next_id)
then
set error_msg = concat('no free ids in range [1, ', cast(max_id as char), ']');
signal sqlstate '45000' set MESSAGE_TEXT = error_msg;
end if;
if next_id > max_id
then
set error_msg = concat('next id too high to insert: next_id=', cast(next_id as char), ' max_id=', cast(max_id as char));
signal sqlstate '45000' set MESSAGE_TEXT = error_msg;
end if;
set NEW.id = next_id;
end
-- host table
CREATE TABLE host (
id INT
-- Other columns may be present
);
-- sequence table (if physical)
CREATE TABLE SEQUENCE_TABLE (
value INT
);
The text was updated successfully, but these errors were encountered:
line 374:21 no viable alternative at input 'CREATE DEFINER=`bcadmin`@`%` TRIGGER `host_id_constraint` BEFORE INSERT ON `host` FOR EACH ROW begin\n declare next_id int;\n declare max_id int;\n declare error_msg varchar(100);\n set max_id = power(2, 9)-1;\n set next_id = null;\n select min(st.value) into next_id\n from SEQUENCE_TABLE('
line 371:27 mismatched input '1' expecting '-'
The text was updated successfully, but these errors were encountered: