SET Statement - IBM DB2 to PostgreSQL Migration

In DB2 the SET statement allows you to assign values to variables in stored procedures, functions or triggers, for example:

IBM DB2:

  CREATE PROCEDURE sp_updateDeptLoc(IN p_loc VARCHAR(25), IN p_deptno CHARACTER(5)) 
  LANGUAGE SQL
  BEGIN
    DECLARE v_loc VARCHAR(25);
    DECLARE v_deptno CHAR(5);
    SET v_loc = p_loc;
    SET v_deptno = p_deptno;
    UPDATE dept SET location = v_loc WHERE deptno = v_deptno;
  END
  /

In PostgreSQL you can use the assignment operator := , the corresponding example:

PostgreSQL:

  CREATE OR REPLACE FUNCTION sp_updateDeptLoc(IN p_loc VARCHAR(25), IN p_deptno CHARACTER(5)) 
  RETURNS VOID 
  AS $$
  DECLARE 
    v_loc VARCHAR(25);
    v_deptno CHAR(5);
  BEGIN
    v_loc := p_loc;
    v_deptno := p_deptno;
    UPDATE dept SET location = v_loc WHERE deptno = v_deptno;
  END;
  $$ LANGUAGE plpgsql;

For more examples, please see IBM DB2 to PostgreSQL Migration Reference