PostgreSQL
MSSQL

MSSQL Query and Function convert to PostgreSQL

  1. PROCEDURE -> FUNCTION AND RETURN VOID;
CREATE OR REPLACE FUNCTION <function name> (value)
RETURNS void AS
$$
BEGIN
 <Procedure body>
END;
$$ LANGUAGE plpgsql VOLATILE;
  1. Data type

    • nvarchar -> varchar
  2. TOP -> LIMIT

  3. IF

    • MSSQL : IF condition BEGIN function END;
    • PostgreSQL : IF condition THEN function END IF;
  4. DYNAMIC SQL
    MSSQL: EXEC query;

PSQL:

EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL BEGIN DECLARE SECTION;
const char *stmt = "CREATE TABLE test1 (...);";
EXEC SQL END DECLARE SECTION;

EXEC SQL EXECUTE IMMEDIATE :stmt;