Re: join from array or cursor

From: Scott Bailey <artacus(at)comcast(dot)net>
To: John DeSoi <desoi(at)pgedit(dot)com>
Cc: pgsql-general List <pgsql-general(at)postgresql(dot)org>
Subject: Re: join from array or cursor
Date: 2009-08-21 04:58:54
Message-ID: 4A8E298E.1000308@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

John DeSoi wrote:
> Suppose I have an integer array (or cursor with one integer column)
> which represents primary keys of some table. Is there a simple and
> efficient way to return the rows of the table corresponding to the
> primary key values and keep them in the same order as the array (or
> cursor)? Seems like it should be easy, but I'm not seeing it.
>
> Thanks,
>
>
> John DeSoi, Ph.D.

Matching the rows is easy. Getting them in the same order as the items
in the array will require an ORDER BY. The contrib package _int has an
idx() that you can use for that.

SELECT *
FROM foo
WHERE foo.id = ANY(myPkArray)
ORDER BY idx(myPkArray, id)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message John R Pierce 2009-08-21 05:24:00 Re: DB Design Advice
Previous Message stoneg64@excite.com 2009-08-21 04:50:28 DB Design Advice