Select Distinct Order By Array_Position

"Mark Williams" <[email protected]> Mon, 26 Nov 2018 19:12:39 -0000
Newsgroups gmane.comp.db.postgresql.sql
Message-ID <[email protected]>
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

__