pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Aasmund Midttun Godal <postgresql@envisity.com>
To: pgsql-sql@postgresql.org
Subject: Error codes as numbers or in other languages etc.
Date: Tue, 23 Oct 2001 17:08:08 GMT
Message-ID: <20011023170808.2262.qmail@ns.krot.org> (raw)

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



Message-ID: <20011023170808.2262.qmail@ns.krot.org>
Permalink:  ../20011023170808.2262.qmail@ns.krot.org/
Also on:    postgresql.org/message-id/20011023170808.2262.qmail@ns.krot.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: postgresql@envisity.com
  Subject: Re: Error codes as numbers or in other languages etc.
  In-Reply-To: <20011023170808.2262.qmail@ns.krot.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox