On Thu, 2 Jun 2005, Tom Lane wrote:
> Pavel Stehule <stehule@kix.fsv.cvut.cz> writes:
> > b) some functions need patch to parser - greatest, least and decode.
>
> Why?
>
they has variable number of argument, they are polymorphic. They are not
functions, more special form of operators.
Maybe it is possible. I don't know PostgreSQL internal structures best,
but I can't to write similar functions without change parser.
Is it possible? I didn't find any example.
And code
for greatest and least is easy now, no more than 100 lines of code. Decode
is more compliceted (like case operator). Least and greatest use equal
functions and decode only different last ExecEvalVarargDecode. And calling
of these functions are much cheeper than calling true function.
Pavel Stehule
the change of parser is minimalistic:
| COALESCE '(' expr_list ')'
{
CoalesceExpr *c =
makeNode(CoalesceExpr);
c->args = $3;
$$ = (Node *)c;
}
| GREATEST '(' expr_list ')'
{
VarargExpr *v =
makeNode(VarargExpr);
v->args = $3;
v->type = IS_GREATEST;
$$ = (Node *)v;
}
| LEAST '(' expr_list ')'
{
VarargExpr *v =
makeNode(VarargExpr);
v->args = $3;
v->type = IS_LEAST;
$$ = (Node *)v;
}
| DECODE '(' expr_list ')'
{
VarargExpr *v =
makeNode(VarargExpr);
v->args = $3;
v->type = IS_DECODE;
$$ = (Node *)v;
}