CREATE CAST question

From: "Robert Wimmer" <seppwimmer(at)hotmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: CREATE CAST question
Date: 2005-08-05 23:04:50
Message-ID: BAY12-F131753E9B50F8831E4ECF2D0C70@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


I have the following problem

I want to define a schema qualified domain and create a cast to cast a
string in the new domain.
This is what i did.

***

CREATE DOMAIN tree.ident AS TEXT;

CREATE OR REPLACE FUNCTION tree.ident_cast(TEXT) RETURNS tree.ident AS '
DECLARE regex TEXT; ret TEXT; l1 INT; l2 INT;
BEGIN
regex := ''^[a-zA-Z0-9][^/%_]*'';
ret := SUBSTRING($1 FROM regex);
l1 := LENGTH($1); l2 := LENGTH(ret);
IF l1 <> l2 THEN RAISE EXCEPTION ''syntax error in "%" at % (%)
'',$1,l2,ret; END IF;
RETURN $1;
END; '
LANGUAGE plpgsql;

CREATE CAST (TEXT AS tree.ident) WITH FUNCTION tree.ident_cast(TEXT) AS
IMPLICIT;

***
the cast function works as expected ...

tree_cal=# SELECT tree.ident_cast('path/node');
ERROR: syntax error in "path/node" at 9 (path)

but if i do the following no error will occur

tree_cal=# SELECT CAST('path/node' AS tree.ident);
path/node

this looks like as if the cast function never whas used ...

what do i have to do that the cast function is called during the cast ?

regards

i am using postgre 7.4 on debian

_________________________________________________________________
Behalten Sie Ihre Hotmails, den Messenger und die Suchfunktionen stets im
Auge! http://toolbar.msn.at?DI=43&XAPID=2170

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2005-08-06 04:20:24 Re: CREATE CAST question
Previous Message Walker, Jed S 2005-08-05 18:40:29 Monitoring postmaster.log