Re: Validating problem in the isn contrib module - Mailing list pgsql-hackers

From Andreas 'ads' Scherbaum
Subject Re: Validating problem in the isn contrib module
Date
Msg-id 20090307004240.0a2c705a@iridium.wars-nicht.de
Whole thread Raw
In response to Re: Validating problem in the isn contrib module  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Fri, 06 Mar 2009 10:27:52 -0500 Tom Lane wrote:

> Judging from the comments, is_valid (and the internal validity bit)
> were a bad design decision that the author later regretted, but felt
> he couldn't change for compatibility reasons.  I'm not sure why not
> ... we make bigger incompatible changes than that all the time.

Looks a bit ugly and the way this module handles the input is unusual.


> The way to validate an ISBN is exactly the same as it is for every
> other data type: feed the string to the input function and see if
> it throws an error.

For the record here's a function which validates a text if it contains
an ISBN-13, similar functions are possible for the other datatypes
defined by isn:


CREATE OR REPLACE FUNCTION validate_isbn13(TEXT)         RETURNS BOOLEAN
AS $$
DECLARE isbn_nr ALIAS FOR $1; weak_status BOOLEAN; isbn_status BOOLEAN;
BEGIN
 -- make sure weak mode is off weak_status := isn_weak(FALSE); -- this will either return 'true' or throw an exception
isbn_status:= is_valid(isbn_nr::isbn13); weak_status := isn_weak(weak_status);
 
 RETURN isbn_status;
 EXCEPTION   -- handle (only) the exception which is thrown by is_valid()   WHEN invalid_text_representation THEN
RETURNfalse;
 
END;
$$
LANGUAGE 'plpgsql';


Bye

--             Andreas 'ads' Scherbaum
German PostgreSQL User Group
European PostgreSQL User Group - Board of Directors


pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Out parameters handling
Next
From: "Holger Hoffstaette"
Date:
Subject: Re: libxml incompatibility