aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_node.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>1999-12-24 06:43:34 +0000
committerTom Lane <tgl@sss.pgh.pa.us>1999-12-24 06:43:34 +0000
commit350cb386af0d5caf5ae32781e80b8622fb5e4fe1 (patch)
tree9bb76439a628b4db461dc4e1fb8f95753e06c009 /src/backend/parser/parse_node.c
parentbd5ea42a8d2f6cf484f9b10d8c13894fe88ee7e8 (diff)
downloadpostgresql-350cb386af0d5caf5ae32781e80b8622fb5e4fe1.tar.gz
postgresql-350cb386af0d5caf5ae32781e80b8622fb5e4fe1.zip
Clean up handling of explicit NULL constants. Cases like
SELECT null::text; SELECT int4fac(null); work as expected now. In some cases a NULL must be surrounded by parentheses: SELECT 2 + null; fails SELECT 2 + (null); OK This is a grammatical ambiguity that seems difficult to avoid. Other than that, NULLs seem to behave about like you'd expect. The internal implementation is that NULL constants are typed as UNKNOWN (like untyped string constants) until the parser can deduce the right type.
Diffstat (limited to 'src/backend/parser/parse_node.c')
-rw-r--r--src/backend/parser/parse_node.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/backend/parser/parse_node.c b/src/backend/parser/parse_node.c
index 2cab730412d..c660df38261 100644
--- a/src/backend/parser/parse_node.c
+++ b/src/backend/parser/parse_node.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.33 1999/11/22 17:56:21 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.34 1999/12/24 06:43:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -61,28 +61,27 @@ make_operand(char *opname,
Oid target_typeId)
{
Node *result;
- Type target_type;
+ Type target_type = typeidType(target_typeId);
if (tree != NULL)
{
- result = tree;
- target_type = typeidType(target_typeId);
- disallow_setop(opname, target_type, result);
-
+ disallow_setop(opname, target_type, tree);
/* must coerce? */
if (target_typeId != orig_typeId)
result = coerce_type(NULL, tree, orig_typeId, target_typeId, -1);
+ else
+ result = tree;
}
- /* otherwise, this is a NULL value */
else
{
+ /* otherwise, this is a NULL value */
Const *con = makeNode(Const);
con->consttype = target_typeId;
- con->constlen = 0;
- con->constvalue = (Datum) (struct varlena *) NULL;
+ con->constlen = typeLen(target_type);
+ con->constvalue = (Datum) NULL;
con->constisnull = true;
- con->constbyval = true;
+ con->constbyval = typeByVal(target_type);
con->constisset = false;
result = (Node *) con;
}
@@ -394,7 +393,8 @@ transformArraySubscripts(ParseState *pstate,
* of the "natural" type for the constant. For strings we produce
* a constant of type UNKNOWN ---- representation is the same as text,
* but this indicates to later type resolution that we're not sure that
- * it should be considered text.
+ * it should be considered text. Explicit "NULL" constants are also
+ * typed as UNKNOWN.
*/
Const *
make_const(Value *value)
@@ -444,7 +444,13 @@ make_const(Value *value)
elog(NOTICE, "make_const: unknown type %d\n", nodeTag(value));
/* return a null const */
- con = makeConst(0, 0, (Datum) NULL, true, false, false, false);
+ con = makeConst(UNKNOWNOID,
+ -1,
+ (Datum) NULL,
+ true,
+ false,
+ false,
+ false);
return con;
}