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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-hackers by date

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