Re: Select Distinct Order By Array_Position

From: Rob Sargent <robjsargent(at)gmail(dot)com>
To: Mark Williams <markwillimas(at)gmail(dot)com>
Cc: pgsql-sql(at)lists(dot)postgresql(dot)org
Subject: Re: Select Distinct Order By Array_Position
Date: 2018-11-26 19:20:14
Message-ID: 57AC3D96-24B8-4D06-8946-AF6E0116888F@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> On Nov 26, 2018, at 12:12 PM, Mark Williams <markwillimas(at)gmail(dot)com> wrote:
>
> Hi,
>
> I am getting an error “SELECT DISTINCT, ORDER BY expressions must appear in select list”. I am ordering by documents.id <http://documents.id/> and it appears in my select list. So I am guessing the problem lies with the array. Is there any way of achieving this? Query is below.
>
> SELECT DISTINCT documents.id <http://documents.id/>, page_no FROM texts LEFT JOIN documents on documents.id <http://documents.id/>=texts.doc_id WHERE doc_id IN (26194, 2345, 189) AND (text LIKE '%RIVER%') ORDER BY array_position(ARRAY[26194, 2345, 189]::INTEGER[], documents.id <http://documents.id/>)
>
> Thanks,
>
> Mark
> __

Try put the array_position clause in the select and add documents.id <http://documents.id/> to the order by?

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message David G. Johnston 2018-11-26 19:46:22 Re: Select Distinct Order By Array_Position
Previous Message Mark Williams 2018-11-26 19:12:39 Select Distinct Order By Array_Position