Thread: a little doubr about domains and pl/python
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
"Walter Cruz" <walter.php@gmail.com> writes: > CREATE CAST (integer AS romano) WITH FUNCTION to_roman(integer); > What's wrong? Domains aren't supported as cast source/targets at the moment; I don't think the system is finding your cast specification at all, but is instead doing this as 5::text::romano which of course fails. See past discussions about the subtleties of trying to fix this. regards, tom lane