Skip site navigation (1) Skip section navigation (2)

a little doubr about domains and pl/python

From: "Walter Cruz" <walter(dot)php(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: a little doubr about domains and pl/python
Date: 2006-09-29 16:25:40
Message-ID: 32cabba0609290925p36c04eaau57e2b250f3175500@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackers
Hi all. I'm playing with pl/python AND i'm with a doubt.

I wanna create a domain to roman numerals.

I have made:

CREATE OR REPLACE FUNCTION valid_roman(text)
RETURNS BOOLEAN
IMMUTABLE
LANGUAGE plpythonu AS
$$
from roman9 import fromRoman

roman = args[0]
try:
   r = fromRoman(roman)
   return 'true'
except:
    return 'false'
$$;

CREATE DOMAIN romano AS text
  CHECK (valid_roman(VALUE))
  ;


CREATE OR REPLACE FUNCTION to_roman(integer)
RETURNS romano
IMMUTABLE
LANGUAGE plpythonu AS
$$
from roman9 import toRoman

number = args[0]
try:
   r = toRoman(number)
   return r
except:
  return 'false'
$$;

CREATE CAST (integer AS romano) WITH FUNCTION to_roman(integer);

And that works:

SELECT to_roman(50)
SELECT to_roman(100)
SELECT valid_roman('XX')
SELECT valid_roman('XXX')
SELECT valid_roman('XXXX')

But my cast doen't works:

SELECT 5::romano

ERROR:  value for domain romano violates check constraint "romano_check"

What's wrong?

[]'s
- Walter

Responses

pgsql-hackers by date

Next:From: Casey DuncanDate: 2006-09-29 16:35:25
Subject: Re: [GENERAL] Array assignment behavior (was Re: Stored procedure array limits)
Previous:From: Heikki LinnakangasDate: 2006-09-29 16:22:27
Subject: Re: Block B-Tree concept

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group