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;
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;
CREATE CAST (TEXT AS tree.ident) WITH FUNCTION tree.ident_cast(TEXT) AS
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);
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 ?
"Robert Wimmer" <[hidden email]> writes:
> I want to define a schema qualified domain and create a cast to cast a
> string in the new domain.
Casts between domains and their underlying types are hard-wired into the
system: you don't get to muck with the semantics by doing CREATE CAST.
The correct way to do this is to define a constraint on the domain,
along the lines of
create function is_ok_ident(text) returns bool as '
... return true if you like the string ...
' language plpgsql;
create domain ident as text check (is_ok_ident(value));
regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not