diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 1999-12-24 06:43:34 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 1999-12-24 06:43:34 +0000 |
commit | 350cb386af0d5caf5ae32781e80b8622fb5e4fe1 (patch) | |
tree | 9bb76439a628b4db461dc4e1fb8f95753e06c009 /src/backend/utils/adt/ruleutils.c | |
parent | bd5ea42a8d2f6cf484f9b10d8c13894fe88ee7e8 (diff) |
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/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 47fd957c994..00099791c09 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -3,7 +3,7 @@ * out of it's tuple * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.35 1999/12/13 01:27:01 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.36 1999/12/24 06:43:34 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -1606,12 +1606,6 @@ get_const_expr(Const *constval, deparse_context *context) char *valptr; bool isnull = FALSE; - if (constval->constisnull) - { - appendStringInfo(buf, "NULL"); - return; - } - typetup = SearchSysCacheTuple(TYPEOID, ObjectIdGetDatum(constval->consttype), 0, 0, 0); @@ -1620,6 +1614,19 @@ get_const_expr(Const *constval, deparse_context *context) typeStruct = (Form_pg_type) GETSTRUCT(typetup); + if (constval->constisnull) + { + /* + * Always label the type of a NULL constant. This not only + * prevents misdecisions about the type, but it ensures that + * our output is a valid b_expr. + */ + extval = pstrdup(NameStr(typeStruct->typname)); + appendStringInfo(buf, "NULL::%s", quote_identifier(extval)); + pfree(extval); + return; + } + fmgr_info(typeStruct->typoutput, &finfo_output); extval = (char *) (*fmgr_faddr(&finfo_output)) (constval->constvalue, &isnull, -1); |