RAISERROR Statement - Sybase SQL Anywhere to PostgreSQL Migration

In Sybase SQL Anywhere, the RAISERROR statement allows you to raise an error.

In PostgreSQL, you can use the RAISE EXCEPTION statement.

Sybase SQL Anywhere:

  -- Raise an error with the error code 99999
  RAISERROR 99999 'Something went ' || 'wrong.';
  /* RAISERROR executed: Something went wrong. SQLCODE=-99999, ODBC 3 State="HY000" */

PostgreSQL:

  DO $$
  BEGIN  
    -- Raise an error with the error code 99999
    RAISE EXCEPTION '%', 'Something went ' || 'wrong.' USING ERRCODE = 99999;
  END;
  $$;
  /* ERROR:  Something went wrong. */

For more information, see Sybase SQL Anywhere to PostgreSQL Migration.