yugabyte/yb-voyager

[MySQL] Generated invalid PLPGSQL using variable assignment/order by on UPDATE statement

ssherwood opened this issue · 0 comments

Jira Link: DB-13457
Running Voyager to migrate a set of stored procedures from MySQL (MariaDB 10.5) and identified a syntax issue:

Original:

CREATE DEFINER=`root`@`localhost` PROCEDURE `UpdateRecordsAndReturn`()
BEGIN
update foo_table set status = 'start' where status = 'init' order by created_dt asc ;
SELECT * FROM foo_table ft  WHERE status  = 'init';
end ;;

Result:

CREATE OR REPLACE PROCEDURE updaterecordsandreturn () AS $body$
BEGIN
update foo_table status := 'start' where status = 'init' order by created_dt asc ;
SELECT * FROM foo_table ft  WHERE status  = 'init';
end;
$body$
LANGUAGE PLPGSQL
SECURITY DEFINER
;

The resulting is invalid syntax in PLPGSQL and it looks as if there are two discrete problems:

  1. In the PLPGSQL there is missing SET and a variable assignment := in an UPDATE ... SET statement.
  2. While MySQL does allow order by on UPDATE statements, this is invalid syntax in Postgres.