pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Garamond <davidgaramond@gmail.com>
To: Pavel Stehule <pavel.stehule@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Array: comparing first N elements?
Date: Tue, 12 May 2009 15:40:02 +0700
Message-ID: <7c33d060905120140p78b4e180rda6101cff30459eb@mail.gmail.com> (raw)
In-Reply-To: <162867790905120128h1dff1ba3mdc9c511af938e595@mail.gmail.com>
References: <7c33d060905120105y74b0483eyf5d94c07912a0702@mail.gmail.com>
	<162867790905120128h1dff1ba3mdc9c511af938e595@mail.gmail.com>

On Tue, May 12, 2009 at 3:28 PM, Pavel Stehule <pavel.stehule@gmail.com>wrote:

> Hello
>
> create or replace function eqn(anyarray, anyarray, int)
> returns boolean as $$
>  select not exists(select $1[i] from generate_series(1,$3) g(i)
>                           except
>                           select $2[i] from generate_series(1,$3) g(i))
> $$ language sql immutable strict;
>
> postgres=# select eqn(array[1,2,3,4,5], array[1,2,3,5,6], 3);
>  eqn
> -----
>  t
> (1 row)
>
> Time: 1,590 ms
> postgres=# select eqn(array[1,2,3,4,5], array[1,2,3,5,6], 4);
>  eqn
> -----
>  f
> (1 row)
>

Hi Pavel,

Thanks for the solution, but that's too slow. I'd rather just do this
instead:

select * from product
where parents[1:(select array_length(parents,1) from product where
name='wanted')+1]=
  (select parents from product where name='wanted')||
  (select id from product where name='wanted');

but the above query is also unable to use any indices (unlike LIKE 'foo%').

Regards,
Dave

view thread (6+ messages)  latest in thread

Message-ID: <7c33d060905120140p78b4e180rda6101cff30459eb@mail.gmail.com>
Permalink:  ../7c33d060905120140p78b4e180rda6101cff30459eb@mail.gmail.com/
Also on:    postgresql.org/message-id/7c33d060905120140p78b4e180rda6101cff30459eb@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: davidgaramond@gmail.com, pavel.stehule@gmail.com
  Subject: Re: Array: comparing first N elements?
  In-Reply-To: <7c33d060905120140p78b4e180rda6101cff30459eb@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox