If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > SQLERRM error in EXCEPTION block

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-19-11, 08:06
pbaxter pbaxter is offline
Registered User
 
Join Date: Jul 2011
Posts: 2
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
Reply With Quote
  #2 (permalink)  
Old 07-25-11, 15:04
futurity futurity is offline
Registered User
 
Join Date: May 2008
Posts: 270
You apparently cannot use a variable directly in a RAISE statement. Try:

RAISE NOTICE '%', SQLERRM;
Reply With Quote
  #3 (permalink)  
Old 07-26-11, 08:12
pbaxter pbaxter is offline
Registered User
 
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?
Reply With Quote
  #4 (permalink)  
Old 07-26-11, 10:28
futurity futurity is offline
Registered User
 
Join Date: May 2008
Posts: 270
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
Reply With Quote
Reply

Tags
exception, sqlerrm

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On