Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2011
    Posts
    2

    Unanswered: SQLERRM error in EXCEPTION block

    I have a BEGIN...EXCEPTION...END block like
    BEGIN
    ......
    EXCEPTION
    WHEN OTHERS THEN
    RAISE NOTICE SQLERRM;
    RETURN 0;
    END;
    that gives this error during CREATE FUNCTION:

    ERROR: syntax error at or near "SQLERRM"
    LINE 220: RAISE NOTICE SQLERRM;

    What am I doing wrong?

    thanks

  2. #2
    Join Date
    May 2008
    Posts
    277
    You apparently cannot use a variable directly in a RAISE statement. Try:

    RAISE NOTICE '%', SQLERRM;

  3. #3
    Join Date
    Jul 2011
    Posts
    2

    Thanks

    Thanks- I'll try that. BTW does '%' do anything special other than just preceding SQLERRM with dummy text?

  4. #4
    Join Date
    May 2008
    Posts
    277
    The RAISE statement takes a string which becomes the message it will display:
    RAISE EXCEPTION 'Invalid values!';

    Variables can be inserted into the string using percent signs:
    RAISE EXCEPTION 'Invalid values: %, %, %', val1, val2, val3;

    PostgreSQL: Documentation: Manuals: PostgreSQL 9.0: Errors and Messages

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •