Unix Technical Forum

cannot get error message after dblink_exec execution

This is a discussion on cannot get error message after dblink_exec execution within the pgsql Admins forums, part of the PostgreSQL category; --> Hi, I am using DBLink contrib module. I cannot catch the dblink_exec error messages. On the other hand, the ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Admins

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 08:07 AM
Sofer, Yuval
 
Posts: n/a
Default cannot get error message after dblink_exec execution

Hi,



I am using DBLink contrib module.

I cannot catch the dblink_exec error messages.

On the other hand, the pgadmin gui shows the error message under
"DETAIL" section:



The test function :



CREATE OR REPLACE FUNCTION test_func1()


RETURNS integer AS

$$

DECLARE

stmt text;

conn text;

err text ;

last_message text default 'aaa';

BEGIN



conn := 'dbname=postgres user=postgres password=manager';

stmt := 'drop table not_existing_table';



err := dblink_exec(conn, stmt,false);

last_message := dblink_error_message('dbname=postgres
user=postgres password=manager') ;

raise notice ' err is %',err;

raise notice ' last_message is %',last_message;

return 0;



END;

$$

LANGUAGE 'plpgsql' VOLATILE;



When I execute select test_func1(); I get the error message from the gui
(table "not_existing table" does not exist):



NOTICE: sql error

DETAIL: ERROR: table "not_existing_table" does not exist



CONTEXT: PL/pgSQL function "test_func1" line 11 at assignment

NOTICE: err is ERROR

NOTICE: last_message is



Total query runtime: 100 ms.

1 rows retrieved.



My questions :

How can catch this error into the stored procedure parameter?

Am I not using dblink_error_message correctly?

I don't mind retrieving the error message as the gui does, but how can I
do it?



Thanks

Yuval

DBA team

BMC Software








Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 08:07 AM
Joe Conway
 
Posts: n/a
Default Re: cannot get error message after dblink_exec execution

Sofer, Yuval wrote:
> last_message := dblink_error_message('dbname=postgres
> user=postgres password=manager') ;



> Am I not using dblink_error_message correctly?


Yes, you are not using dblink_error_message correctly. From the docs:

================================================== ================
Name

dblink_error_message -- gets last error message on the named connection

Synopsis

dblink_error_message(text connname) RETURNS text

Inputs

connname
The specific connection name to use.

Outputs

Returns last error message.

Example usage

SELECT dblink_error_message('dtest1');
================================================== ================

It requires a named connection, you are trying to use an anonymous one.

HTH,

Joe

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:30 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com