Re: How to eliminate extra "NOT EXISTS"-query here?

2023-11-28 Thread hector vass
Not equivalent to the use of NOT ARRAY and entirely possible I have misunderstood the requirement ...do you have some more test cases the non array solution does not work for Regards Hector Vass 07773 352559 On Mon, Nov 27, 2023 at 9:29 AM Dominique Devienne wrote: > On Sat, Nov 25, 2023 at

Re: How to eliminate extra "NOT EXISTS"-query here?

2023-11-27 Thread Dominique Devienne
On Sat, Nov 25, 2023 at 5:53 PM hector vass wrote: > Not sure you need to use array why not simple table joins, so a table with > your criteria x y z t joined to stuff to give you candidates that do match, > then left join with coalesce to add the 'd' > > select > > --a.id,b.test_id, > >

Re: How to eliminate extra "NOT EXISTS"-query here?

2023-11-25 Thread Andreas Joseph Krogh
På lørdag 25. november 2023 kl. 17:08:28, skrev Tom Lane mailto:t...@sss.pgh.pa.us>>: Andreas Joseph Krogh writes: > -- This works, but I'd rather not do the extra EXISTS > select * from test t > WHERE (NOT ARRAY ['x', 'y', 'z', 't']::varchar[] <@ (select array_agg(s.v) from > stuffs WHERE

Re: How to eliminate extra "NOT EXISTS"-query here?

2023-11-25 Thread hector vass
Not sure you need to use array why not simple table joins, so a table with your criteria x y z t joined to stuff to give you candidates that do match, then left join with coalesce to add the 'd' select --a.id,b.test_id, coalesce(a.id,b.test_id) as finalresult from test a left join ( select

Re: How to eliminate extra "NOT EXISTS"-query here?

2023-11-25 Thread Tom Lane
Andreas Joseph Krogh writes: > -- This works, but I'd rather not do the extra EXISTS > select * from test t > WHERE (NOT ARRAY ['x', 'y', 'z', 't']::varchar[] <@ (select array_agg(s.v) > from > stuffs WHERE s.test_id = t.id) > OR NOT EXISTS ( > select * from stuff s where s.test_id = t.id > ) >

How to eliminate extra "NOT EXISTS"-query here?

2023-11-25 Thread Andreas Joseph Krogh
Hi, I'm testing if some dataset contains an array of elements and want to return all “not containing the specified array”, including entries in master table not being referenced. I have the following schema: drop table if exists stuff; drop table if exists test; CREATE TABLE test( id