postgresqlplpgsqlpostgresql-8.2

Syntax Error near SQLSTATE


I got a plpgsql function here to indicate if any warning raised during ANALYZE:

CREATE OR REPLACE FUNCTION analyzeWarning() RETURNS integer AS $$
DECLARE
  warningRaised int;
BEGIN
  warningRaised := 0;
  FOR i IN 1..10
  LOOP
    BEGIN
      ANALYZE;
    EXCEPTION
      WHEN SQLSTATE '01000' THEN return 1;
    END;
  END LOOP;
  RETURN 0;
END;
$$ LANGUAGE plpgsql;

This function kept giving me syntax error near:

ERROR:  syntax error at or near "SQLSTATE"
LINE 11:           WHEN SQLSTATE '01000' THEN return 1;

I am not sure where I missed the syntax error.

My postgres build is 8.2.15.


Solution

  • PostgreSQL 8.2.15 is pretty old unsupported release. This release doesn't support SQLSTATE constant there.

    But your code should not to work on any PostgreSQL release. You cannot to trap warnings or notices in PostgreSQL. Only exceptions are trappable.