Re: How to overload POSITION

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Troels Arvin <troels(at)arvin(dot)dk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to overload POSITION
Date: 2004-11-16 20:56:00
Message-ID: 2309.1100638560@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Troels Arvin <troels(at)arvin(dot)dk> writes:
> I assume this is because the POSITION function uses "IN" to separate
> arguments, in stead of a comma. Is there a way to overload it?

Double-quote "position" in the create function command --- it's a
keyword.

Be aware also of the argument order gotcha. Per gram.y:

| POSITION '(' position_list ')'
{
/* position(A in B) is converted to position(B, A) */
FuncCall *n = makeNode(FuncCall);
n->funcname = SystemFuncName("position");
n->args = $3;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
$$ = (Node *)n;
}

Come to think of it, you'll also need to create your function in the
pg_catalog schema, because that's implied by SystemFuncName(). Which
means it won't get dumped by pg_dump. How wedded are you to being able
to say "IN"?

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Troels Arvin 2004-11-16 21:12:53 Re: How to overload POSITION
Previous Message Greg Stark 2004-11-16 20:44:43 Re: OID's