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) regards Pavel Stehule 2009/5/12 David Garamond <davidgaram...@gmail.com>: > I have a "materialized path" tree table like this (simplified): > CREATE TABLE product ( > id SERIAL PRIMARY KEY, > parents INT[] NOT NULL, > name TEXT NOT NULL, > UNIQUE (parents, name) > ); > CREATE INDEX name ON product(name); > > Previously I use TEXT column for parents, but arrays look interesting and > convenient so I'm considering migrating to arrays. However, how do I rewrite > this using arrays? > SELECT * FROM product > WHERE parents LIKE '0001/0010/%'; > In other words, testing against the first N elements in an array. > Regards, > Dave -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql