Array: comparing first N elements? - Mailing list pgsql-sql

From David Garamond
Subject Array: comparing first N elements?
Date
Msg-id 7c33d060905120105y74b0483eyf5d94c07912a0702@mail.gmail.com
Whole thread Raw
Responses Re: Array: comparing first N elements?
Re: Array: comparing first N elements?
Re: Array: comparing first N elements?
List pgsql-sql
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 

pgsql-sql by date:

Previous
From: "John Lister"
Date:
Subject: Re: Query planning question
Next
From: David Garamond
Date:
Subject: Re: Array: comparing first N elements?