CREATE CAST question - Mailing list pgsql-novice

From Robert Wimmer
Subject CREATE CAST question
Date
Msg-id BAY12-F131753E9B50F8831E4ECF2D0C70@phx.gbl
Whole thread Raw
Responses Re: CREATE CAST question
List 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


pgsql-novice by date:

Previous
From: "Walker, Jed S"
Date:
Subject: Monitoring postmaster.log
Next
From: Tom Lane
Date:
Subject: Re: CREATE CAST question