Received: from ns.krot.org (ns.krot.org [193.212.103.165]) by postgresql.org (8.11.3/8.11.4) with SMTP id f9NHAdP46919 for ; Tue, 23 Oct 2001 13:10:41 -0400 (EDT) (envelope-from postgresql@envisity.com) Received: (qmail 14505 invoked by uid 67); 23 Oct 2001 17:08:08 -0000 Message-ID: <20011023170808.2262.qmail@ns.krot.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Disposition: inline MIME-Version: 1.0 From: "Aasmund Midttun Godal" To: pgsql-sql@postgresql.org Subject: Error codes as numbers or in other languages etc. Date: Tue, 23 Oct 2001 17:08:08 GMT X-Mailer: Googley-Moogley Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by postgresql.org id f9NKV4N99039 X-Archive-Number: 200110/333 X-Sequence-Number: 5286 I have seen several people asking about getting error numbers or similar things out of postgres. The way I have done this is as follows: CREATE TABLE errors ( errorstring TEXT PRIMARY KEY, message TEXT ); INSERT INTO errors VALUES ('^FATAL 1: Database "([^\"]+)" does not exist in the system catalog.$', 'FATALE 1: Le database "$1" n''existe pas dans le catalogue systeme'); Now in the app if we use perl and DBI we set RaiseError => 1 and catch the error via $dbh->errstr or something pass it into a query like: prepare('SELECT * FROM errors WHERE ? ~ errorstring'); #Isn't postgres great? reverse regular expression searches :) my $s = execute($dbh->errstr); then we exploit perl's ability: $dbh->errstr =~ /$s->{'errorstring'}/"$s->{'message'}"/e; Hopes someone else find it usefull, Getting out numbers is offcourse even easier. Aasmund Midttun Godal aasmund@godal.com - http://www.godal.com/ +47 40 45 20 46