1

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.