Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Trigger (DDL) - Debezium parsing error #917

Open
subkanthi opened this issue Nov 15, 2024 · 1 comment
Open

Create Trigger (DDL) - Debezium parsing error #917

subkanthi opened this issue Nov 15, 2024 · 1 comment
Milestone

Comments

@subkanthi
Copy link
Collaborator

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
);

@subkanthi subkanthi added this to the 2.6.0 milestone Nov 15, 2024
@subkanthi
Copy link
Collaborator Author

Debezium error

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 '-'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant