Re: Validating problem in the isn contrib module

Поиск
Список
Период
Сортировка
От Andreas 'ads' Scherbaum
Тема Re: Validating problem in the isn contrib module
Дата
Msg-id 20090307004240.0a2c705a@iridium.wars-nicht.de
обсуждение исходный текст
Ответ на Re: Validating problem in the isn contrib module  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: Out parameters handling
Следующее
От: "Holger Hoffstaette"
Дата:
Сообщение: Re: libxml incompatibility