Oracle to PG: Dollar quote stored procedure body

SQL pattern

In Postgres, function and procedure bodies need to be wrapped in $$dollar quotes$$. This pattern wraps a PLSQL CREATE PROCEDURE body in dollar quotes and adds a language specifier.


Apply with the Grit CLI
grit apply oracle_quote_procedure

Basic procedure

BEFORE
CREATE PROCEDURE remove_emp (employee_id int) AS
   tot_emps int;
   BEGIN
      DELETE FROM employees
      WHERE employees.employee_id = remove_emp.employee_id;
   tot_emps := tot_emps - 1;
   END;
AFTER
CREATE PROCEDURE remove_emp (employee_id int) AS
   DECLARE
 tot_emps int;
   $$BEGIN
      DELETE FROM employees
      WHERE employees.employee_id = remove_emp.employee_id;
   tot_emps := tot_emps - 1;
   END;
$$ LANGUAGE plpgsql;