Re: Validating problem in the isn contrib module

From: Andreas 'ads' Scherbaum <adsmail(at)wars-nicht(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Validating problem in the isn contrib module
Date: 2009-03-06 23:42:40
Message-ID: 20090307004240.0a2c705a@iridium.wars-nicht.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
RETURN false;
END;
$$
LANGUAGE 'plpgsql';

Bye

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Holger Hoffstaette 2009-03-06 23:48:56 Re: libxml incompatibility
Previous Message Alvaro Herrera 2009-03-06 22:57:43 Re: Out parameters handling