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

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to