mirror of
https://github.com/postgres/postgres.git
synced 2025-07-09 22:41:56 +03:00
Modify all callers of datatype input and receive functions so that if these
functions are not strict, they will be called (passing a NULL first parameter) during any attempt to input a NULL value of their datatype. Currently, all our input functions are strict and so this commit does not change any behavior. However, this will make it possible to build domain input functions that centralize checking of domain constraints, thereby closing numerous holes in our domain support, as per previous discussion. While at it, I took the opportunity to introduce convenience functions InputFunctionCall, OutputFunctionCall, etc to use in code that calls I/O functions. This eliminates a lot of grotty-looking casts, but the main motivation is to make it easier to grep for these places if we ever need to touch them again.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.135 2006/03/05 15:58:33 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.136 2006/04/04 19:35:34 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -166,26 +166,21 @@ coerce_type(ParseState *pstate, Node *node,
|
||||
newcon->constbyval = typeByVal(targetType);
|
||||
newcon->constisnull = con->constisnull;
|
||||
|
||||
/*
|
||||
* We pass typmod -1 to the input routine, primarily because
|
||||
* existing input routines follow implicit-coercion semantics for
|
||||
* length checks, which is not always what we want here. Any
|
||||
* length constraint will be applied later by our caller.
|
||||
*
|
||||
* We assume here that UNKNOWN's internal representation is the
|
||||
* same as CSTRING.
|
||||
*/
|
||||
if (!con->constisnull)
|
||||
{
|
||||
/*
|
||||
* We assume here that UNKNOWN's internal representation is the
|
||||
* same as CSTRING
|
||||
*/
|
||||
char *val = DatumGetCString(con->constvalue);
|
||||
|
||||
/*
|
||||
* We pass typmod -1 to the input routine, primarily because
|
||||
* existing input routines follow implicit-coercion semantics for
|
||||
* length checks, which is not always what we want here. Any
|
||||
* length constraint will be applied later by our caller.
|
||||
*
|
||||
* Note that we call stringTypeDatum using the domain's pg_type
|
||||
* row, if it's a domain. This works because the domain row has
|
||||
* the same typinput and typelem as the base type --- ugly...
|
||||
*/
|
||||
newcon->constvalue = stringTypeDatum(targetType, val, -1);
|
||||
}
|
||||
newcon->constvalue = stringTypeDatum(targetType,
|
||||
DatumGetCString(con->constvalue),
|
||||
-1);
|
||||
else
|
||||
newcon->constvalue = stringTypeDatum(targetType, NULL, -1);
|
||||
|
||||
result = (Node *) newcon;
|
||||
|
||||
|
Reference in New Issue
Block a user