Re: Array: comparing first N elements?
От | David Garamond |
---|---|
Тема | Re: Array: comparing first N elements? |
Дата | |
Msg-id | 7c33d060905120140p78b4e180rda6101cff30459eb@mail.gmail.com обсуждение исходный текст |
Ответ на | Array: comparing first N elements? (David Garamond <davidgaramond@gmail.com>) |
Список | pgsql-sql |
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%').
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
В списке pgsql-sql по дате отправления: