diff --git a/doc/src/sgml/ref/create_cast.sgml b/doc/src/sgml/ref/create_cast.sgml index 964cbf4d41..29ea298a46 100644 --- a/doc/src/sgml/ref/create_cast.sgml +++ b/doc/src/sgml/ref/create_cast.sgml @@ -288,6 +288,11 @@ SELECT CAST ( 2 AS numeric ) + 4.0; convert between data types and a second to apply the modifier. + + A cast to or from a domain type currently has no effect. Casting + to or from a domain uses the casts associated with its underlying type. + + diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index 4125b97e89..5f1c19eb37 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -1517,6 +1517,17 @@ CreateCast(CreateCastStmt *stmt) aclcheck_error(aclresult, ACL_KIND_TYPE, format_type_be(targettypeid)); + /* Domains are allowed for historical reasons, but we warn */ + if (sourcetyptype == TYPTYPE_DOMAIN) + ereport(WARNING, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cast will be ignored because the source data type is a domain"))); + + else if (targettyptype == TYPTYPE_DOMAIN) + ereport(WARNING, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cast will be ignored because the target data type is a domain"))); + /* Detemine the cast method */ if (stmt->func != NULL) castmethod = COERCION_METHOD_FUNCTION; diff --git a/src/test/regress/expected/privileges.out b/src/test/regress/expected/privileges.out index a816cce1b1..dfaf3a7a7e 100644 --- a/src/test/regress/expected/privileges.out +++ b/src/test/regress/expected/privileges.out @@ -571,6 +571,7 @@ CREATE DOMAIN testdomain2b AS testdomain1; CREATE DOMAIN testdomain3b AS int; CREATE FUNCTION castfunc(int) RETURNS testdomain3b AS $$ SELECT $1::testdomain3b $$ LANGUAGE SQL; CREATE CAST (testdomain1 AS testdomain3b) WITH FUNCTION castfunc(int); +WARNING: cast will be ignored because the source data type is a domain CREATE FUNCTION testfunc5b(a testdomain1) RETURNS int LANGUAGE SQL AS $$ SELECT $1 $$; CREATE FUNCTION testfunc6b(b int) RETURNS testdomain1 LANGUAGE SQL AS $$ SELECT $1::testdomain1 $$; CREATE OPERATOR !! (PROCEDURE = testfunc5b, RIGHTARG = testdomain1);