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

[MySQL] Generated invalid PLPGSQL using EXIT HANDLER block #1366

Open
ssherwood opened this issue Mar 14, 2024 · 0 comments
Open

[MySQL] Generated invalid PLPGSQL using EXIT HANDLER block #1366

ssherwood opened this issue Mar 14, 2024 · 0 comments
Labels
triage Needs to be triaged

Comments

@ssherwood
Copy link

Running Voyager to migrate a set of stored procedures from MySQL (MariaDB 10.5) and identified a syntax issue with an exit handler:

Original:

...
  DECLARE EXIT HANDLER FOR SQLEXCEPTION
  BEGIN
	get diagnostics CONDITION 1 @sqlstate = returned_sqlstate,
	@errno = mysql_errno,
	@text = message_text;
    
	SET @full_error = CONCAT(
  	"ERROR ",
  	@errno,
  	" (",
  	@sqlstate,
  	"): ",
  	@text
	);
    
	SELECT
  	@full_error;
    
  END;
...

Results:

...
	SET full_error = CONCAT(
  	'ERROR ',
  	errno,
  	' (',
  	sqlstate,
  	'): ',
  	text
	);
    
	SELECT
  	full_error;
    
  END;
...

The result is missing a proper begin and loses additional statements. In general, this block seems largely difficult to translate into Postgres without some effort.

Sample logic we have used to replace this block by hand looks like this (which is applied at the end of the procedure):

  EXCEPTION WHEN others then
        GET STACKED DIAGNOSTICS
            v_state   = RETURNED_SQLSTATE,
            v_msg     = MESSAGE_TEXT,
            v_detail  = PG_EXCEPTION_DETAIL,
            v_hint    = PG_EXCEPTION_HINT,
            v_context = PG_EXCEPTION_CONTEXT;
        raise notice E'Got exception:
            state  : %
            message: %
            detail : %
            hint   : %
            context: %', v_state, v_msg, v_detail, v_hint, v_context;
@github-actions github-actions bot added the triage Needs to be triaged label Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Needs to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant