Re: death of array?

From: Rob Sargent <robjsargent(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: death of array?
Date: 2017-04-08 21:07:43
Message-ID: CED7D0FC-59B7-4F15-9F72-A879907BC210@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


> On Apr 7, 2017, at 10:17 AM, Rob Sargent <robjsargent(at)gmail(dot)com> wrote:
>
>
> On 04/07/2017 10:02 AM, David G. Johnston wrote:
>> On Fri, Apr 7, 2017 at 8:57 AM, Rob Sargent <robjsargent(at)gmail(dot)com> wrote:
>> Understood but true if any match is found, I need every array member to match as I want them all to be of a specific people as input into the query (so field = all(array_col)) and "field" here would be people_member.person_id and using that yields zero results in full query (very quickly though).
>>
>> ​I didn't actually attempt to comprehend your original email. If you want to supply a self-contained, functioning, query and expected output (ideally something simpler but that covers your main question) I'd be inclined to dig further. Even a broken one with what you think should work would be
>>
>> person = ALL(persons) doesn't really seem like it will typically work.
>>
>> Here are the various array operators supplied by PostgreSQL. You might find one of them helpful. In particular "contains".
>>
>> https://www.postgresql.org/docs/9.6/static/functions-array.html
>>
>> David J.
>>
>> ​
>
> Well you prodding got me a seriously reduced execution time. Here's the actual query. The tables are all in the 'seg' schema and not substantively different than described in first post.
>
> create temp table opt10aut
> as
> with optset as (
> select s.id
> , s.markerset_id
> , s.startbase
> , s.endbase
> , ((s.events_equal + s.events_greater)/(1.0 * (s.events_less + s.events_equal + s.events_greater))) as pval
> from seg.segment s
> join seg.probandset i on s.probandset_id = i.id
> join (select people_id, array_agg(person_id) as persons from seg.people_member group by people_id) as pa on i.probands <@ pa.persons
> join seg.people o on pa.people_id = o.id
> where
> s.markerset_id = '61801888-9a81-4187-922c-4d42c0471bea'
> and o.name = '709'
> )
> select m.name
> , min(pval)
> from optset op
> join seg.markerset_member mm on op.markerset_id = mm.markerset_id
> join seg.marker m on mm.member_id = m.id
> where
> m.basepos between op.startbase and op.endbase
> group by m.name
>
> It is true that this particular people has only 60 members. Our upper end would be ~1000.
>
> rjs
>
>
>

What I was hoping for, I guess, is a construct like
create table t(id int /*for Achilles*/, idset int[] references v.field)
and it would be understood that each element can be found in (preferably the index of) v.field
Oh, and an operator to make use of the knowledge something like
select * from t join v on t.idset “are_all_in” v.field;

Thanks to all,
rjs

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleas Mantzios 2017-04-10 06:50:16 Re: death of array?
Previous Message Rob Sargent 2017-04-07 16:17:18 Re: death of array?