Обсуждение: - pl/pgSQL - How can I intercept an eventual exception and put it in a text ?
- pl/pgSQL - How can I intercept an eventual exception and put it in a text ?
От
"Bruno Baguette"
Дата:
Hello, Here's a pl/pgSQL function that simply add a two values inside a table. CREATE function tuple_add(VARCHAR(200)) RETURNS text AS ' DECLARE Response text; PeopleName ALIAS FOR $1; BEGIN INSERT INTO PEOPLES VALUES (nextval(''sequence_id''),PeopleName); return Response; END; ' LANGUAGE 'plpgsql'; If the user try to add the same value (for the PeopleName field), PostGreSQL will throw an exception and print "ERROR: Cannot insert a duplicate key into unique index biblio_maisonsediti_libelle_key ". How can I intercept ANY exception inside the function, and to put in the "Response" variable the text of the EXCEPTION ? In other words, I want to avoid to have my function to throw any exception, so I want to intercept an eventual exception and to take the text ("ERROR: Cannot insert a duplicate key into unique index biblio_maisonsediti_libelle_key" for example) and to put it in the "Response" variable so the program that call my function will receive the error message. Thanks in advance for your help ! :-) ------------------------------------------------- Bruno BAGUETTE - bruno.baguette@netcourrier.com