RE: Select Distinct Order By Array_Position

Поиск
Список
Период
Сортировка
От Mark Williams
Тема RE: Select Distinct Order By Array_Position
Дата
Msg-id 004e01d485c2$6c45cb50$44d161f0$@gmail.com
обсуждение исходный текст
Ответ на Re: Select Distinct Order By Array_Position  (Rob Sargent <robjsargent@gmail.com>)
Ответы Re: Select Distinct Order By Array_Position
Список pgsql-sql

Wasn’t aware it was possible to put array_position statement in the actual select or is this a select within a select?

 

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?

 

__

 

From: Rob Sargent <robjsargent@gmail.com>
Sent: 26 November 2018 19:20
To: Mark Williams <markwillimas@gmail.com>
Cc: pgsql-sql@lists.postgresql.org
Subject: Re: Select Distinct Order By Array_Position

 

 



On Nov 26, 2018, at 12:12 PM, Mark Williams <markwillimas@gmail.com> wrote:

 

Hi,

 

I am getting an error “SELECT DISTINCT, ORDER BY expressions must appear in select list”. I am ordering by 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, page_no FROM texts LEFT JOIN documents on 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)

 

Thanks,

 

Mark

__

 

Try put the array_position clause in the select and add documents.id to the order by?

 

В списке pgsql-sql по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Select Distinct Order By Array_Position
Следующее
От: "Mark Williams"
Дата:
Сообщение: RE: Select Distinct Order By Array_Position