RE: Select Distinct Order By Array_Position

From: "Mark Williams" <markwillimas(at)gmail(dot)com>
To: "'David G(dot) Johnston'" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "'Rob Sargent'" <robjsargent(at)gmail(dot)com>, "'pgsql-sql'" <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: RE: Select Distinct Order By Array_Position
Date: 2018-11-26 20:22:28
Message-ID: 005601d485c5$c1303300$43909900$@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Many thanks. I'll mess around with what you've sent and see if I can get it working.

__

-----Original Message-----
From: David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
Sent: 26 November 2018 20:07
To: Mark Williams <markwillimas(at)gmail(dot)com>
Cc: Rob Sargent <robjsargent(at)gmail(dot)com>; pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: Select Distinct Order By Array_Position

On Mon, Nov 26, 2018 at 12:58 PM Mark Williams <markwillimas(at)gmail(dot)com> wrote:
>
> Wasn’t aware it was possible to put array_position statement in the actual select or is this a select within a select?

Easy enough to try either way

> Also, I am selecting from an ordered (randomly) subset of data and I need to return the result set in the same order so do have to output the array as part of the order by?

Not sure what the question is...

Anyway, maybe this will be helpful:

SELECT vals.*
FROM (VALUES (1::integer),(2),(3),(4),(5)) vals (v), LATERAL unnest(ARRAY[3,1,5]::integer[]) with ordinality AS spec (s, o) WHERE v = s ORDER BY o

David J.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Olivier Leprêtre 2018-11-28 08:32:54 error code 8
Previous Message David G. Johnston 2018-11-26 20:06:46 Re: Select Distinct Order By Array_Position