From 51972a9d5d068dd34b24ff4923981ffb90e5cc2d Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 16 Feb 2003 02:30:39 +0000 Subject: COALESCE() and NULLIF() are now first-class expressions, not macros that turn into CASE expressions. They evaluate their arguments at most once. Patch by Kris Jurka, review and (very light) editorializing by me. --- src/backend/nodes/readfuncs.c | 47 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'src/backend/nodes/readfuncs.c') diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index f37856728b1..410d092c916 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.148 2003/02/09 06:56:27 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.149 2003/02/16 02:30:37 tgl Exp $ * * NOTES * Path and Plan nodes do not have any readfuncs support, because we @@ -606,6 +606,47 @@ _readCaseWhen(void) READ_DONE(); } +/* + * _readCoalesceExpr + */ +static CoalesceExpr * +_readCoalesceExpr(void) +{ + READ_LOCALS(CoalesceExpr); + + READ_OID_FIELD(coalescetype); + READ_NODE_FIELD(args); + + READ_DONE(); +} + +/* + * _readNullIfExpr + */ +static NullIfExpr * +_readNullIfExpr(void) +{ + READ_LOCALS(NullIfExpr); + + READ_OID_FIELD(opno); + READ_OID_FIELD(opfuncid); + /* + * The opfuncid is stored in the textual format primarily for debugging + * and documentation reasons. We want to always read it as zero to force + * it to be re-looked-up in the pg_operator entry. This ensures that + * stored rules don't have hidden dependencies on operators' functions. + * (We don't currently support an ALTER OPERATOR command, but might + * someday.) + */ + local_node->opfuncid = InvalidOid; + + READ_OID_FIELD(opresulttype); + READ_BOOL_FIELD(opretset); + READ_NODE_FIELD(args); + + READ_DONE(); +} + /* * _readNullTest */ @@ -895,6 +936,10 @@ parseNodeString(void) return_value = _readCaseExpr(); else if (MATCH("WHEN", 4)) return_value = _readCaseWhen(); + else if (MATCH("COALESCE", 8)) + return_value = _readCoalesceExpr(); + else if (MATCH("NULLIFEXPR", 10)) + return_value = _readNullIfExpr(); else if (MATCH("NULLTEST", 8)) return_value = _readNullTest(); else if (MATCH("BOOLEANTEST", 11)) -- cgit v1.2.3