pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Glenn Maynard <glennfmaynard@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Array: comparing first N elements?
Date: Tue, 12 May 2009 04:37:24 -0400
Message-ID: <bd36f99e0905120137o498af74dh19720c1059b39532@mail.gmail.com> (raw)
In-Reply-To: <7c33d060905120105y74b0483eyf5d94c07912a0702@mail.gmail.com>
References: <7c33d060905120105y74b0483eyf5d94c07912a0702@mail.gmail.com>

On Tue, May 12, 2009 at 4:05 AM, David Garamond <davidgaramond@gmail.com> wrote:
> 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.

SELECT * FROM product
WHERE parents[1] = 1 AND parents[2] = 2;

I'd expect there to be a way to index this, on individual components
or a slice, eg.

CREATE INDEX parents_1 ON product(parents[1]);
CREATE INDEX parents_2to4 ON product(parents[2], parents[3], parents[4]);

... but this throws a parse error.  I don't have an immediate need for
this, but I'm curious if this is possible--it seems a natural part of
having a native array type.

-- 
Glenn Maynard



view thread (6+ messages)  latest in thread

Message-ID: <bd36f99e0905120137o498af74dh19720c1059b39532@mail.gmail.com>
Permalink:  ../bd36f99e0905120137o498af74dh19720c1059b39532@mail.gmail.com/
Also on:    postgresql.org/message-id/bd36f99e0905120137o498af74dh19720c1059b39532@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: glennfmaynard@gmail.com
  Subject: Re: Array: comparing first N elements?
  In-Reply-To: <bd36f99e0905120137o498af74dh19720c1059b39532@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