aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/commands/functioncmds.c22
-rw-r--r--src/backend/nodes/copyfuncs.c3
-rw-r--r--src/backend/nodes/equalfuncs.c3
-rw-r--r--src/backend/parser/gram.y15
-rw-r--r--src/backend/parser/parse_coerce.c24
5 files changed, 53 insertions, 14 deletions
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 12762b8aaab..80a57457ee5 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.99 2008/10/21 10:38:51 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.100 2008/10/31 08:39:20 heikki Exp $
*
* DESCRIPTION
* These routines take the parse tree and pick out the
@@ -1383,6 +1383,7 @@ CreateCast(CreateCastStmt *stmt)
Oid funcid;
int nargs;
char castcontext;
+ char castmethod;
Relation relation;
HeapTuple tuple;
Datum values[Natts_pg_cast];
@@ -1415,7 +1416,15 @@ CreateCast(CreateCastStmt *stmt)
format_type_be(sourcetypeid),
format_type_be(targettypeid))));
+ /* Detemine the cast method */
if (stmt->func != NULL)
+ castmethod = COERCION_METHOD_FUNCTION;
+ else if(stmt->inout)
+ castmethod = COERCION_METHOD_INOUT;
+ else
+ castmethod = COERCION_METHOD_BINARY;
+
+ if (castmethod == COERCION_METHOD_FUNCTION)
{
Form_pg_proc procstruct;
@@ -1476,6 +1485,12 @@ CreateCast(CreateCastStmt *stmt)
}
else
{
+ funcid = InvalidOid;
+ nargs = 0;
+ }
+
+ if (castmethod == COERCION_METHOD_BINARY)
+ {
int16 typ1len;
int16 typ2len;
bool typ1byval;
@@ -1483,10 +1498,6 @@ CreateCast(CreateCastStmt *stmt)
char typ1align;
char typ2align;
- /* indicates binary coercibility */
- funcid = InvalidOid;
- nargs = 0;
-
/*
* Must be superuser to create binary-compatible casts, since
* erroneous casts can easily crash the backend.
@@ -1562,6 +1573,7 @@ CreateCast(CreateCastStmt *stmt)
values[Anum_pg_cast_casttarget - 1] = ObjectIdGetDatum(targettypeid);
values[Anum_pg_cast_castfunc - 1] = ObjectIdGetDatum(funcid);
values[Anum_pg_cast_castcontext - 1] = CharGetDatum(castcontext);
+ values[Anum_pg_cast_castmethod - 1] = CharGetDatum(castmethod);
MemSet(nulls, ' ', Natts_pg_cast);
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index 2dce7bab18f..d56075e6bbf 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.409 2008/10/21 20:42:52 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.410 2008/10/31 08:39:20 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -3042,6 +3042,7 @@ _copyCreateCastStmt(CreateCastStmt *from)
COPY_NODE_FIELD(targettype);
COPY_NODE_FIELD(func);
COPY_SCALAR_FIELD(context);
+ COPY_SCALAR_FIELD(inout);
return newnode;
}
diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c
index e0b8bdcecb1..e17aff89228 100644
--- a/src/backend/nodes/equalfuncs.c
+++ b/src/backend/nodes/equalfuncs.c
@@ -22,7 +22,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.334 2008/10/21 20:42:52 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.335 2008/10/31 08:39:20 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1666,6 +1666,7 @@ _equalCreateCastStmt(CreateCastStmt *a, CreateCastStmt *b)
COMPARE_NODE_FIELD(targettype);
COMPARE_NODE_FIELD(func);
COMPARE_SCALAR_FIELD(context);
+ COMPARE_SCALAR_FIELD(inout);
return true;
}
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 8b44e5b6ba4..b78d5b302e3 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.632 2008/10/29 11:24:53 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.633 2008/10/31 08:39:20 heikki Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -4590,6 +4590,7 @@ CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
n->targettype = $6;
n->func = $10;
n->context = (CoercionContext) $11;
+ n->inout = false;
$$ = (Node *)n;
}
| CREATE CAST '(' Typename AS Typename ')'
@@ -4600,6 +4601,18 @@ CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
n->targettype = $6;
n->func = NULL;
n->context = (CoercionContext) $10;
+ n->inout = false;
+ $$ = (Node *)n;
+ }
+ | CREATE CAST '(' Typename AS Typename ')'
+ WITH INOUT cast_context
+ {
+ CreateCastStmt *n = makeNode(CreateCastStmt);
+ n->sourcetype = $4;
+ n->targettype = $6;
+ n->func = NULL;
+ n->context = (CoercionContext) $10;
+ n->inout = true;
$$ = (Node *)n;
}
;
diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c
index 6d703ae5718..112a07beb58 100644
--- a/src/backend/parser/parse_coerce.c
+++ b/src/backend/parser/parse_coerce.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.170 2008/10/25 17:19:09 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.171 2008/10/31 08:39:21 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1909,11 +1909,23 @@ find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId,
/* Rely on ordering of enum for correct behavior here */
if (ccontext >= castcontext)
{
- *funcid = castForm->castfunc;
- if (OidIsValid(*funcid))
- result = COERCION_PATH_FUNC;
- else
- result = COERCION_PATH_RELABELTYPE;
+ switch (castForm->castmethod)
+ {
+ case COERCION_METHOD_FUNCTION:
+ result = COERCION_PATH_FUNC;
+ *funcid = castForm->castfunc;
+ break;
+ case COERCION_METHOD_INOUT:
+ result = COERCION_PATH_COERCEVIAIO;
+ break;
+ case COERCION_METHOD_BINARY:
+ result = COERCION_PATH_RELABELTYPE;
+ break;
+ default:
+ elog(ERROR, "unrecognized castmethod: %d",
+ (int) castForm->castmethod);
+ break;
+ }
}
ReleaseSysCache(tuple);