Re: join from array or cursor

From: Greg Stark <gsstark(at)mit(dot)edu>
To: John DeSoi <desoi(at)pgedit(dot)com>
Cc: Sam Mason <sam(at)samason(dot)me(dot)uk>, pgsql-general(at)postgresql(dot)org
Subject: Re: join from array or cursor
Date: 2009-08-21 13:22:54
Message-ID: 407d949e0908210622q1fc0efdfxca73756df371d0b4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Aug 21, 2009 at 2:16 PM, Greg Stark<gsstark(at)mit(dot)edu> wrote:
> On Fri, Aug 21, 2009 at 1:16 PM, John DeSoi<desoi(at)pgedit(dot)com> wrote:
>>
>> Yes, this is the best I have come up with so far. I have a set returning
>> function which returns the key and the index number. The implementation with
>> a cursor looks like this:
>>
>> SELECT * FROM cursor_pk('c1') c LEFT JOIN foo ON (c.pk = foo.pk) ORDER BY
>> c.idx;
>
> This might be a circumstance where it's really best to just force the
> planner to use a particular plan. There's no way to tell it "the order
> of the array" without forcing an entirely unnecessary sort.

Of course immediately upon hitting send I did think of a way:

SELECT (r).*
FROM (SELECT (SELECT x FROM x WHERE a=id) AS r
FROM unnest(array[1,2]) AS arr(id)
) AS subq;

--
greg
http://mit.edu/~gsstark/resume.pdf

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2009-08-21 13:44:43 Re: Questions about encoding between two databases
Previous Message Greg Stark 2009-08-21 13:16:33 Re: join from array or cursor