8000 Casts to or from a domain type are ignored; warn and document. · jandas/postgres@3ce7f18 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ce7f18

Browse files
committed
Casts to or from a domain type are ignored; warn and document.
Prohibiting this outright would break dumps taken from older versions that contain such casts, which would create far more pain than is justified here. Per report by Jaime Casanova and subsequent discussion.
1 parent e4f06b7 commit 3ce7f18

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

doc/src/sgml/ref/create_cast.sgml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
288288
convert between data types and a second to apply the modifier.
289289
</para>
290290

291+
<para>
292+
A cast to or from a domain type currently has no effect. Casting
293+
to or from a domain uses the casts associated with its underlying type.
294+
</para>
295+
291296
</refsect1>
292297

293298
<refsect1 id="sql-createcast-notes">

src/backend/commands/functioncmds.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,17 @@ CreateCast(CreateCastStmt *stmt)
15171517
aclcheck_error(aclresult, ACL_KIND_TYPE,
15181518
format_type_be(targettypeid));
15191519

1520+
/* Domains are allowed for historical reasons, but we warn */
1521+
if (sourcetyptype == TYPTYPE_DOMAIN)
1522+
ereport(WARNING,
1523+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1524+
errmsg("cast will be ignored because the source data type is a domain")));
1525+
1526+
else if (targettyptype == TYPTYPE_DOMAIN)
1527+
ereport(WARNING,
1528+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1529+
errmsg("cast will be ignored because the target data type is a domain")));
1530+
15201531
/* Detemine the cast method */
15211532
if (stmt->func != NULL)
15221533
castmethod = COERCION_METHOD_FUNCTION;

src/test/regress/expected/privileges.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ CREATE DOMAIN testdomain2b AS testdomain1;
571571
CREATE DOMAIN testdomain3b AS int;
572572
CREATE FUNCTION castfunc(int) RETURNS testdomain3b AS $$ SELECT $1::testdomain3b $$ LANGUAGE SQL;
573573
CREATE CAST (testdomain1 AS testdomain3b) WITH FUNCTION castfunc(int);
574+
WARNING: cast will be ignored because the source data type is a domain
574575
CREATE FUNCTION testfunc5b(a testdomain1) RETURNS int LANGUAGE SQL AS $$ SELECT $1 $$;
575576
CREATE FUNCTION testfunc6b(b int) RETURNS testdomain1 LANGUAGE SQL AS $$ SELECT $1::testdomain1 $$;
576577
CREATE OPERATOR !! (PROCEDURE = testfunc5b, RIGHTARG = testdomain1);

0 commit comments

Comments
 (0)
0