X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 77A463CC288 for ; Sat, 18 Dec 2004 10:17:38 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 12799-06 for ; Sat, 18 Dec 2004 10:17:29 +0000 (GMT) Received: from hotmail.com (bay10-f26.bay10.hotmail.com [64.4.37.26]) by svr1.postgresql.org (Postfix) with ESMTP id 569D13A91D7 for ; Sat, 18 Dec 2004 10:17:30 +0000 (GMT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Sat, 18 Dec 2004 02:16:00 -0800 Message-ID: Received: from 62.178.117.119 by by10fd.bay10.hotmail.msn.com with HTTP; Sat, 18 Dec 2004 10:15:06 GMT X-Originating-IP: [62.178.117.119] X-Originating-Email: [seppwimmer@hotmail.com] X-Sender: seppwimmer@hotmail.com In-Reply-To: From: "Robert Wimmer" To: andreas_kretschmer@despammed.com, pgsql-interfaces@postgresql.org Subject: Re: plpgsql errorcodes Date: Sat, 18 Dec 2004 10:15:06 +0000 Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed X-OriginalArrivalTime: 18 Dec 2004 10:16:00.0636 (UTC) FILETIME=[929B7BC0:01C4E4EA] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.994 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_POST, MSGID_FROM_MTA_HEADER X-Spam-Level: X-Archive-Number: 200412/40 X-Sequence-Number: 5210 >From: Andreas Kretschmer >To: pgsql-interfaces@postgresql.org >Subject: Re: [INTERFACES] plpgsql errorcodes >Date: Fri, 17 Dec 2004 17:52:00 +0100 > >begin "Robert Wimmer" wrote: > > i want the DB functionality to be done by the server. this means i want >to > > write functions like > > > CREATE FUNCTION insert_any(....) RETURNS INT AS ' > > BEGIN > > > END; ' > > LANGUAGE 'plpgsql' > > > returning an errorcode so i can map this errorcode to a message for the >user > > of the client. and i want to do this on the server without using any > >You can use RAISE to generate a error. > >end >Andreas hi andreas, RAISE NOTICE wouldnt help, because it would never be executed if a runtime error occurs. a short example. CREATE TABLE dummy ( id SERIAL ... name VARCHAR(20) , code INT CONSTRAINT codeNotUnique UNIQUE, first DATE); -- this function controls data before inserting CREATE FUNCTION insert_dummy(TEXT, TEXT, TEXT) RETURNS INTEGER AS ' DECLARE dat DATE; BEGIN dat := CAST($3 AS DATE); -- if an error occurs execution will be stopped i cant drop any notice -- i would like todo something like if ERROR != 0 THEN RETURN -1; END IF; -- cannot convert to date INSERT INTO dummy(name, code, first) VALUES($1,$2,$3); if CONSTRAINT-ERROR = codeNotUnique THEN RETURN -2 END IF; -- you cant do that, you have to do the following -- the SELECT will be done again internal from psql SELECT INTO tmp * FROM dummy WHERE code = CAST($2 AS INTEGER); IF FOUND THEN RETURN -2 END IF; -- everything is OK RETURN 0; END; ' LANGUAGE plpgsql; my problem is, all plpgsql does is fine. but you do not get any errorcode during the function. and outside the function the errormessages cannot be used the generate a usefull errorcode. its just some english text. i hope you can understand what i am talking about, bye sepp _________________________________________________________________ Sie wollen unterwegs am Handy Nachrichten von Messenger-Freunden erhalten? http://www.msn.at/msnmobile/