Re: IN and ANY

From: Joe Conway <mail(at)joeconway(dot)com>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: IN and ANY
Date: 2004-03-03 03:53:40
Message-ID: 404556C4.6050908@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Greg Stark wrote:
> So in this case if argL or argR are functions or other expressions with
> unknown types it tries to figure out how to interpret them to produce the type
> it's looking for. In other words, what type those expressions are depends on
> what the expression expects. What would you do with "foo() IN (array[1,2])" if
> there are two functions called foo, one which returns an integer and one which
> returns an integer[] ?

Well, first off, it isn't now, nor has it ever been (to my knowledge),
possible to overload a function with more than one return type. It also
isn't possible to declare a polymorphic return type unless at least one
argument is polymorphic (meaning there must be at least one argument),
in which case the return type is absolutely deterministic at time of
execution.

I'm not sure it's worth discussing this too much further, due to Tom's
objection to the concept in general, but anyway...you should use the
source. Starting with gram.y, we have this:

r_expr: row IN_P select_with_parens
{
SubLink *n = makeNode(SubLink);
n->subLinkType = ANY_SUBLINK;
n->lefthand = $1;
n->operName = makeList1(makeString("="));
n->subselect = $3;
$$ = (Node *)n;
}

Here you can see that "IN" is actually transformed internally
to an "= ANY" SubLink node. In parse_expr.c you'll see (around line 518
in current sources) where the ANY SubLink is processed. Note that
exprType() is used on the expressions in order to determine
(recursively) the argument data types, so that the appropriate operator
can be picked. Hence, if we *wanted* to know if exprType(right_expr) was
an array of exprType(left_expr), we could.

> One of these days I'm going to suggest doing away with the whole "unknown"
> concept and make function return types not part of the polymorphic signature.
> That would make a lot of the type system weirdness go away. But it would mean
> breaking with a lot of tradition.

That doesn't make too much sense either. Polymorphic return types were
not possible prior to 7.4.

Joe

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2004-03-03 04:12:23 Re: Out of space situation and WAL log pre-allocation (was Tablespaces)
Previous Message Tom Lane 2004-03-03 03:52:49 Re: Tablespaces