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/copyfuncs.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'src/backend/nodes/copyfuncs.c') diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index aa7a7efcc8b..2698f084787 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 - * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.243 2003/02/10 04:44:44 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.244 2003/02/16 02:30:37 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -785,7 +785,7 @@ _copyOpExpr(OpExpr *from) } /* - * _copyDistinctExpr + * _copyDistinctExpr (same as OpExpr) */ static DistinctExpr * _copyDistinctExpr(DistinctExpr *from) @@ -919,6 +919,37 @@ _copyCaseWhen(CaseWhen *from) return newnode; } +/* + * _copyCoalesceExpr + */ +static CoalesceExpr * +_copyCoalesceExpr(CoalesceExpr *from) +{ + CoalesceExpr *newnode = makeNode(CoalesceExpr); + + COPY_SCALAR_FIELD(coalescetype); + COPY_NODE_FIELD(args); + + return newnode; +} + +/* + * _copyNullIfExpr (same as OpExpr) + */ +static NullIfExpr * +_copyNullIfExpr(NullIfExpr *from) +{ + NullIfExpr *newnode = makeNode(NullIfExpr); + + COPY_SCALAR_FIELD(opno); + COPY_SCALAR_FIELD(opfuncid); + COPY_SCALAR_FIELD(opresulttype); + COPY_SCALAR_FIELD(opretset); + COPY_NODE_FIELD(args); + + return newnode; +} + /* * _copyNullTest */ @@ -2484,6 +2515,12 @@ copyObject(void *from) case T_CaseWhen: retval = _copyCaseWhen(from); break; + case T_CoalesceExpr: + retval = _copyCoalesceExpr(from); + break; + case T_NullIfExpr: + retval = _copyNullIfExpr(from); + break; case T_NullTest: retval = _copyNullTest(from); break; -- cgit v1.2.3