<!--
-$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.259 2005/06/24 20:53:29 tgl Exp $
+$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.260 2005/06/26 22:05:35 tgl Exp $
PostgreSQL documentation
-->
</sect2>
+ <sect2>
+ <title><literal>GREATEST</literal> and <literal>LEAST</literal></title>
+
+ <indexterm>
+ <primary>GREATEST</primary>
+ </indexterm>
+ <indexterm>
+ <primary>LEAST</primary>
+ </indexterm>
+
+<synopsis>
+<function>GREATEST</function>(<replaceable>value</replaceable> <optional>, ...</optional>)
+</synopsis>
+<synopsis>
+<function>LEAST</function>(<replaceable>value</replaceable> <optional>, ...</optional>)
+</synopsis>
+
+ <para>
+ The <function>GREATEST</> and <function>LEAST</> functions select the
+ largest or smallest value from a list of any number of expressions.
+ The expressions must all be convertible to a common data type, which
+ will be the type of the result
+ (see <xref linkend="typeconv-union-case"> for details). NULL values
+ in the list are ignored. The result will be NULL only if all the
+ expressions evaluate to NULL.
+ </para>
+
+ <para>
+ Note that <function>GREATEST</> and <function>LEAST</> are not in
+ the SQL standard, but are a common extension.
+ </para>
+ </sect2>
+
</sect1>
<!--
-$PostgreSQL: pgsql/doc/src/sgml/typeconv.sgml,v 1.43 2004/12/23 23:07:38 tgl Exp $
+$PostgreSQL: pgsql/doc/src/sgml/typeconv.sgml,v 1.44 2005/06/26 22:05:36 tgl Exp $
-->
<chapter Id="typeconv">
</varlistentry>
<varlistentry>
<term>
-<literal>UNION</literal>, <literal>CASE</literal>, and <literal>ARRAY</literal> constructs
+<literal>UNION</literal>, <literal>CASE</literal>, and related constructs
</term>
<listitem>
<para>
<command>SELECT</> clause must be matched up and converted to a uniform set.
Similarly, the result expressions of a <literal>CASE</> construct must be
converted to a common type so that the <literal>CASE</> expression as a whole
-has a known output type. The same holds for <literal>ARRAY</> constructs.
+has a known output type. The same holds for <literal>ARRAY</> constructs,
+and for the <function>GREATEST</> and <function>LEAST</> functions.
</para>
</listitem>
</varlistentry>
</sect1>
<sect1 id="typeconv-union-case">
-<title><literal>UNION</literal>, <literal>CASE</literal>, and <literal>ARRAY</literal> Constructs</title>
+<title><literal>UNION</literal>, <literal>CASE</literal>, and Related Constructs</title>
<indexterm zone="typeconv-union-case">
<primary>UNION</primary>
<secondary>determination of result type</secondary>
</indexterm>
+<indexterm zone="typeconv-union-case">
+ <primary>GREATEST</primary>
+ <secondary>determination of result type</secondary>
+</indexterm>
+
+<indexterm zone="typeconv-union-case">
+ <primary>LEAST</primary>
+ <secondary>determination of result type</secondary>
+</indexterm>
+
<para>
SQL <literal>UNION</> constructs must match up possibly dissimilar
types to become a single result set. The resolution algorithm is
applied separately to each output column of a union query. The
<literal>INTERSECT</> and <literal>EXCEPT</> constructs resolve
dissimilar types in the same way as <literal>UNION</>. The
-<literal>CASE</> and <literal>ARRAY</> constructs use the identical
+<literal>CASE</>, <literal>ARRAY</>, <function>GREATEST</> and
+<function>LEAST</> constructs use the identical
algorithm to match up their component expressions and select a result
data type.
</para>
<procedure>
-<title><literal>UNION</literal>, <literal>CASE</literal>, and
-<literal>ARRAY</literal> Type Resolution</title>
+<title>Type Resolution for <literal>UNION</literal>, <literal>CASE</literal>,
+and Related Constructs</title>
<step performance="required">
<para>
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.179 2005/05/12 20:41:56 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.180 2005/06/26 22:05:36 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static Datum ExecEvalCoalesce(CoalesceExprState *coalesceExpr,
ExprContext *econtext,
bool *isNull, ExprDoneCond *isDone);
+static Datum ExecEvalMinMax(MinMaxExprState *minmaxExpr,
+ ExprContext *econtext,
+ bool *isNull, ExprDoneCond *isDone);
static Datum ExecEvalNullIf(FuncExprState *nullIfExpr,
ExprContext *econtext,
bool *isNull, ExprDoneCond *isDone);
return (Datum) 0;
}
+/* ----------------------------------------------------------------
+ * ExecEvalMinMax
+ * ----------------------------------------------------------------
+ */
+static Datum
+ExecEvalMinMax(MinMaxExprState *minmaxExpr, ExprContext *econtext,
+ bool *isNull, ExprDoneCond *isDone)
+{
+ Datum result = (Datum) 0;
+ MinMaxOp op = ((MinMaxExpr *) minmaxExpr->xprstate.expr)->op;
+ FunctionCallInfoData locfcinfo;
+ ListCell *arg;
+
+ if (isDone)
+ *isDone = ExprSingleResult;
+ *isNull = true; /* until we get a result */
+
+ InitFunctionCallInfoData(locfcinfo, &minmaxExpr->cfunc, 2, NULL, NULL);
+ locfcinfo.argnull[0] = false;
+ locfcinfo.argnull[1] = false;
+
+ foreach(arg, minmaxExpr->args)
+ {
+ ExprState *e = (ExprState *) lfirst(arg);
+ Datum value;
+ bool valueIsNull;
+ int32 cmpresult;
+
+ value = ExecEvalExpr(e, econtext, &valueIsNull, NULL);
+ if (valueIsNull)
+ continue; /* ignore NULL inputs */
+
+ if (*isNull)
+ {
+ /* first nonnull input, adopt value */
+ result = value;
+ *isNull = false;
+ }
+ else
+ {
+ /* apply comparison function */
+ locfcinfo.arg[0] = result;
+ locfcinfo.arg[1] = value;
+ locfcinfo.isnull = false;
+ cmpresult = DatumGetInt32(FunctionCallInvoke(&locfcinfo));
+ if (locfcinfo.isnull) /* probably should not happen */
+ continue;
+ if (cmpresult > 0 && op == IS_LEAST)
+ result = value;
+ else if (cmpresult < 0 && op == IS_GREATEST)
+ result = value;
+ }
+ }
+
+ return result;
+}
+
/* ----------------------------------------------------------------
* ExecEvalNullIf
*
state = (ExprState *) cstate;
}
break;
+ case T_MinMaxExpr:
+ {
+ MinMaxExpr *minmaxexpr = (MinMaxExpr *) node;
+ MinMaxExprState *mstate = makeNode(MinMaxExprState);
+ List *outlist = NIL;
+ ListCell *l;
+ TypeCacheEntry *typentry;
+
+ mstate->xprstate.evalfunc = (ExprStateEvalFunc) ExecEvalMinMax;
+ foreach(l, minmaxexpr->args)
+ {
+ Expr *e = (Expr *) lfirst(l);
+ ExprState *estate;
+
+ estate = ExecInitExpr(e, parent);
+ outlist = lappend(outlist, estate);
+ }
+ mstate->args = outlist;
+ /* Look up the btree comparison function for the datatype */
+ typentry = lookup_type_cache(minmaxexpr->minmaxtype,
+ TYPECACHE_CMP_PROC);
+ if (!OidIsValid(typentry->cmp_proc))
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_FUNCTION),
+ errmsg("could not identify a comparison function for type %s",
+ format_type_be(minmaxexpr->minmaxtype))));
+ fmgr_info(typentry->cmp_proc, &(mstate->cfunc));
+ state = (ExprState *) mstate;
+ }
+ break;
case T_NullIfExpr:
{
NullIfExpr *nullifexpr = (NullIfExpr *) node;
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.308 2005/06/22 21:14:29 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.309 2005/06/26 22:05:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
return newnode;
}
+/*
+ * _copyMinMaxExpr
+ */
+static MinMaxExpr *
+_copyMinMaxExpr(MinMaxExpr *from)
+{
+ MinMaxExpr *newnode = makeNode(MinMaxExpr);
+
+ COPY_SCALAR_FIELD(minmaxtype);
+ COPY_SCALAR_FIELD(op);
+ COPY_NODE_FIELD(args);
+
+ return newnode;
+}
+
/*
* _copyNullIfExpr (same as OpExpr)
*/
case T_CoalesceExpr:
retval = _copyCoalesceExpr(from);
break;
+ case T_MinMaxExpr:
+ retval = _copyMinMaxExpr(from);
+ break;
case T_NullIfExpr:
retval = _copyNullIfExpr(from);
break;
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.245 2005/06/22 21:14:29 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.246 2005/06/26 22:05:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
return true;
}
+static bool
+_equalMinMaxExpr(MinMaxExpr *a, MinMaxExpr *b)
+{
+ COMPARE_SCALAR_FIELD(minmaxtype);
+ COMPARE_SCALAR_FIELD(op);
+ COMPARE_NODE_FIELD(args);
+
+ return true;
+}
+
static bool
_equalNullIfExpr(NullIfExpr *a, NullIfExpr *b)
{
case T_CoalesceExpr:
retval = _equalCoalesceExpr(a, b);
break;
+ case T_MinMaxExpr:
+ retval = _equalMinMaxExpr(a, b);
+ break;
case T_NullIfExpr:
retval = _equalNullIfExpr(a, b);
break;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.255 2005/06/09 04:18:58 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.256 2005/06/26 22:05:37 tgl Exp $
*
* NOTES
* Every node type that can appear in stored rules' parsetrees *must*
WRITE_NODE_FIELD(args);
}
+static void
+_outMinMaxExpr(StringInfo str, MinMaxExpr *node)
+{
+ WRITE_NODE_TYPE("MINMAX");
+
+ WRITE_OID_FIELD(minmaxtype);
+ WRITE_ENUM_FIELD(op, MinMaxOp);
+ WRITE_NODE_FIELD(args);
+}
+
static void
_outNullIfExpr(StringInfo str, NullIfExpr *node)
{
case T_CoalesceExpr:
_outCoalesceExpr(str, obj);
break;
+ case T_MinMaxExpr:
+ _outMinMaxExpr(str, obj);
+ break;
case T_NullIfExpr:
_outNullIfExpr(str, obj);
break;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.178 2005/06/05 22:32:54 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.179 2005/06/26 22:05:37 tgl Exp $
*
* NOTES
* Path and Plan nodes do not have any readfuncs support, because we
READ_DONE();
}
+/*
+ * _readMinMaxExpr
+ */
+static MinMaxExpr *
+_readMinMaxExpr(void)
+{
+ READ_LOCALS(MinMaxExpr);
+
+ READ_OID_FIELD(minmaxtype);
+ READ_ENUM_FIELD(op, MinMaxOp);
+ READ_NODE_FIELD(args);
+
+ READ_DONE();
+}
+
/*
* _readNullIfExpr
*/
return_value = _readRowExpr();
else if (MATCH("COALESCE", 8))
return_value = _readCoalesceExpr();
+ else if (MATCH("MINMAX", 6))
+ return_value = _readMinMaxExpr();
else if (MATCH("NULLIFEXPR", 10))
return_value = _readNullIfExpr();
else if (MATCH("NULLTEST", 8))
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.198 2005/06/05 22:32:56 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.199 2005/06/26 22:05:38 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
return false;
if (IsA(node, CoalesceExpr))
return false;
+ if (IsA(node, MinMaxExpr))
+ return false;
if (IsA(node, NullIfExpr))
return false;
return true;
if (IsA(node, CoalesceExpr))
return true;
+ if (IsA(node, MinMaxExpr))
+ return true;
if (IsA(node, NullIfExpr))
return true;
if (IsA(node, NullTest))
newargs = lappend(newargs, newcasewhen);
continue;
}
-
+
/*
* Found a TRUE condition, so none of the remaining alternatives
* can be reached. We treat the result as the default result.
return walker(((RowExpr *) node)->args, context);
case T_CoalesceExpr:
return walker(((CoalesceExpr *) node)->args, context);
+ case T_MinMaxExpr:
+ return walker(((MinMaxExpr *) node)->args, context);
case T_NullIfExpr:
return walker(((NullIfExpr *) node)->args, context);
case T_NullTest:
return (Node *) newnode;
}
break;
+ case T_MinMaxExpr:
+ {
+ MinMaxExpr *minmaxexpr = (MinMaxExpr *) node;
+ MinMaxExpr *newnode;
+
+ FLATCOPY(newnode, minmaxexpr, MinMaxExpr);
+ MUTATE(newnode->args, minmaxexpr->args, List *);
+ return (Node *) newnode;
+ }
+ break;
case T_NullIfExpr:
{
NullIfExpr *expr = (NullIfExpr *) node;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.497 2005/06/24 14:28:06 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.498 2005/06/26 22:05:38 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
FALSE_P FETCH FIRST_P FLOAT_P FOR FORCE FOREIGN FORWARD
FREEZE FROM FULL FUNCTION
- GLOBAL GRANT GROUP_P
+ GLOBAL GRANT GREATEST GROUP_P
HANDLER HAVING HEADER HOLD HOUR_P
KEY
- LANCOMPILER LANGUAGE LARGE_P LAST_P LEADING LEFT LEVEL LIKE LIMIT
- LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP LOCATION
+ LANCOMPILER LANGUAGE LARGE_P LAST_P LEADING LEAST LEFT LEVEL
+ LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP LOCATION
LOCK_P
MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
AlterTableStmt *n = makeNode(AlterTableStmt);
n->relation = $3;
n->cmds = $4;
- n->relkind = OBJECT_TABLE;
+ n->relkind = OBJECT_TABLE;
$$ = (Node *)n;
}
| ALTER INDEX relation_expr alter_rel_cmds
/*****************************************************************************
*
- * ALTER THING name OWNER TO newname.
+ * ALTER THING name OWNER TO newname.
*
*****************************************************************************/
(Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6)),
(Node *) makeA_Expr(AEXPR_AND, NIL,
(Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6),
- (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4)));
+ (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4)));
}
| a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
{
(Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7)),
(Node *) makeA_Expr(AEXPR_OR, NIL,
(Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7),
- (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5)));
+ (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5)));
}
| a_expr IN_P in_expr
{
c->args = $3;
$$ = (Node *)c;
}
+ | GREATEST '(' expr_list ')'
+ {
+ MinMaxExpr *v = makeNode(MinMaxExpr);
+ v->args = $3;
+ v->op = IS_GREATEST;
+ $$ = (Node *)v;
+ }
+ | LEAST '(' expr_list ')'
+ {
+ MinMaxExpr *v = makeNode(MinMaxExpr);
+ v->args = $3;
+ v->op = IS_LEAST;
+ $$ = (Node *)v;
+ }
;
/*
| EXISTS
| EXTRACT
| FLOAT_P
+ | GREATEST
| INOUT
| INT_P
| INTEGER
| INTERVAL
+ | LEAST
| NATIONAL
| NCHAR
| NONE
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/keywords.c,v 1.158 2005/06/22 21:14:30 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/keywords.c,v 1.159 2005/06/26 22:05:39 tgl Exp $
*
*-------------------------------------------------------------------------
*/
{"function", FUNCTION},
{"global", GLOBAL},
{"grant", GRANT},
+ {"greatest", GREATEST},
{"group", GROUP_P},
{"handler", HANDLER},
{"having", HAVING},
{"large", LARGE_P},
{"last", LAST_P},
{"leading", LEADING},
+ {"least", LEAST},
{"left", LEFT},
{"level", LEVEL},
{"like", LIKE},
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.183 2005/06/04 20:56:13 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.184 2005/06/26 22:05:39 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static Node *transformArrayExpr(ParseState *pstate, ArrayExpr *a);
static Node *transformRowExpr(ParseState *pstate, RowExpr *r);
static Node *transformCoalesceExpr(ParseState *pstate, CoalesceExpr *c);
+static Node *transformMinMaxExpr(ParseState *pstate, MinMaxExpr *m);
static Node *transformBooleanTest(ParseState *pstate, BooleanTest *b);
static Node *transformColumnRef(ParseState *pstate, ColumnRef *cref);
static Node *transformWholeRowRef(ParseState *pstate, char *schemaname,
result = transformCoalesceExpr(pstate, (CoalesceExpr *) expr);
break;
+ case T_MinMaxExpr:
+ result = transformMinMaxExpr(pstate, (MinMaxExpr *) expr);
+ break;
+
case T_NullTest:
{
NullTest *n = (NullTest *) expr;
return (Node *) newc;
}
+static Node *
+transformMinMaxExpr(ParseState *pstate, MinMaxExpr *m)
+{
+ MinMaxExpr *newm = makeNode(MinMaxExpr);
+ List *newargs = NIL;
+ List *newcoercedargs = NIL;
+ List *typeids = NIL;
+ ListCell *args;
+
+ newm->op = m->op;
+ foreach(args, m->args)
+ {
+ Node *e = (Node *) lfirst(args);
+ Node *newe;
+
+ newe = transformExpr(pstate, e);
+ newargs = lappend(newargs, newe);
+ typeids = lappend_oid(typeids, exprType(newe));
+ }
+
+ newm->minmaxtype = select_common_type(typeids, "GREATEST/LEAST");
+
+ /* Convert arguments if necessary */
+ foreach(args, newargs)
+ {
+ Node *e = (Node *) lfirst(args);
+ Node *newe;
+
+ newe = coerce_to_common_type(pstate, e,
+ newm->minmaxtype,
+ "GREATEST/LEAST");
+ newcoercedargs = lappend(newcoercedargs, newe);
+ }
+
+ newm->args = newcoercedargs;
+ return (Node *) newm;
+}
+
static Node *
transformBooleanTest(ParseState *pstate, BooleanTest *b)
{
case T_CoalesceExpr:
type = ((CoalesceExpr *) expr)->coalescetype;
break;
+ case T_MinMaxExpr:
+ type = ((MinMaxExpr *) expr)->minmaxtype;
+ break;
case T_NullIfExpr:
type = exprType((Node *) linitial(((NullIfExpr *) expr)->args));
break;
return typmod;
}
break;
+ case T_MinMaxExpr:
+ {
+ /*
+ * If all the alternatives agree on type/typmod, return
+ * that typmod, else use -1
+ */
+ MinMaxExpr *mexpr = (MinMaxExpr *) expr;
+ Oid minmaxtype = mexpr->minmaxtype;
+ int32 typmod;
+ ListCell *arg;
+
+ typmod = exprTypmod((Node *) linitial(mexpr->args));
+ foreach(arg, mexpr->args)
+ {
+ Node *e = (Node *) lfirst(arg);
+
+ if (exprType(e) != minmaxtype)
+ return -1;
+ if (exprTypmod(e) != typmod)
+ return -1;
+ }
+ return typmod;
+ }
+ break;
case T_NullIfExpr:
{
NullIfExpr *nexpr = (NullIfExpr *) expr;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.136 2005/06/05 00:38:10 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.137 2005/06/26 22:05:40 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* make coalesce() act like a regular function */
*name = "coalesce";
return 2;
+ case T_MinMaxExpr:
+ /* make greatest/least act like a regular function */
+ switch (((MinMaxExpr*) node)->op)
+ {
+ case IS_GREATEST:
+ *name = "greatest";
+ return 2;
+ case IS_LEAST:
+ *name = "least";
+ return 2;
+ }
+ break;
default:
break;
}
* back to source text
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.200 2005/06/05 00:38:10 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.201 2005/06/26 22:05:40 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
case T_ArrayExpr:
case T_RowExpr:
case T_CoalesceExpr:
+ case T_MinMaxExpr:
case T_NullIfExpr:
case T_Aggref:
case T_FuncExpr:
case T_BoolExpr: /* lower precedence */
case T_ArrayRef: /* other separators */
case T_ArrayExpr: /* other separators */
- case T_RowExpr: /* other separators */
+ case T_RowExpr: /* other separators */
case T_CoalesceExpr: /* own parentheses */
+ case T_MinMaxExpr: /* own parentheses */
case T_NullIfExpr: /* other separators */
- case T_Aggref: /* own parentheses */
+ case T_Aggref: /* own parentheses */
case T_CaseExpr: /* other separators */
return true;
default:
}
case T_ArrayRef: /* other separators */
case T_ArrayExpr: /* other separators */
- case T_RowExpr: /* other separators */
+ case T_RowExpr: /* other separators */
case T_CoalesceExpr: /* own parentheses */
+ case T_MinMaxExpr: /* own parentheses */
case T_NullIfExpr: /* other separators */
- case T_Aggref: /* own parentheses */
+ case T_Aggref: /* own parentheses */
case T_CaseExpr: /* other separators */
return true;
default:
}
break;
+ case T_MinMaxExpr:
+ {
+ MinMaxExpr *minmaxexpr = (MinMaxExpr *) node;
+
+ switch (minmaxexpr->op)
+ {
+ case IS_GREATEST:
+ appendStringInfo(buf, "GREATEST(");
+ break;
+ case IS_LEAST:
+ appendStringInfo(buf, "LEAST(");
+ break;
+ }
+ get_rule_expr((Node *) minmaxexpr->args, context, true);
+ appendStringInfoChar(buf, ')');
+ }
+ break;
+
case T_NullIfExpr:
{
NullIfExpr *nullifexpr = (NullIfExpr *) node;
bool need_paren_on_right;
need_paren_on_right = PRETTY_PAREN(context) &&
- !IsA(j->rarg, RangeTblRef) &&
+ !IsA(j->rarg, RangeTblRef) &&
!(IsA(j->rarg, JoinExpr) && ((JoinExpr*) j->rarg)->alias != NULL);
if (!PRETTY_PAREN(context) || j->alias != NULL)
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.135 2005/06/20 18:37:02 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.136 2005/06/26 22:05:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
List *args; /* the arguments */
} CoalesceExprState;
+/* ----------------
+ * MinMaxExprState node
+ * ----------------
+ */
+typedef struct MinMaxExprState
+{
+ ExprState xprstate;
+ List *args; /* the arguments */
+ FmgrInfo cfunc; /* lookup info for comparison func */
+} MinMaxExprState;
+
/* ----------------
* CoerceToDomainState node
* ----------------
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/nodes.h,v 1.170 2005/06/09 04:19:00 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/nodes.h,v 1.171 2005/06/26 22:05:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
T_ArrayExpr,
T_RowExpr,
T_CoalesceExpr,
+ T_MinMaxExpr,
T_NullIfExpr,
T_NullTest,
T_BooleanTest,
T_ArrayExprState,
T_RowExprState,
T_CoalesceExprState,
+ T_MinMaxExprState,
T_CoerceToDomainState,
T_DomainConstraintState,
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.107 2005/04/06 16:34:07 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.108 2005/06/26 22:05:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
List *args; /* the arguments */
} CoalesceExpr;
+/*
+ * MinMaxExpr - a GREATEST or LEAST function
+ */
+typedef enum MinMaxOp
+{
+ IS_GREATEST,
+ IS_LEAST
+} MinMaxOp;
+
+typedef struct MinMaxExpr
+{
+ Expr xpr;
+ Oid minmaxtype; /* common type of arguments and result */
+ MinMaxOp op; /* function to execute */
+ List *args; /* the arguments */
+} MinMaxExpr;
+
/*
* NullIfExpr - a NULLIF expression
*
* procedural language
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.148 2005/06/22 07:28:47 neilc Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.149 2005/06/26 22:05:42 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
return TRUE;
}
+ case T_MinMaxExpr:
+ {
+ MinMaxExpr *expr = (MinMaxExpr *) node;
+
+ if (!exec_simple_check_node((Node *) expr->args))
+ return FALSE;
+
+ return TRUE;
+ }
+
case T_NullIfExpr:
{
NullIfExpr *expr = (NullIfExpr *) node;