pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Andreas Joseph Krogh <andreak@officenet.no>
Cc: pgsql-sql@postgresql.org
Subject: Re: Alternative to INTERSECT
Date: Tue, 31 Jul 2007 14:09:07 -0700 (PDT)
Message-ID: <20070731140503.F67596@megazone.bigpanda.com> (raw)
In-Reply-To: <200707311730.51280.andreak@officenet.no>
References: <200707311730.51280.andreak@officenet.no>

On Tue, 31 Jul 2007, Andreas Joseph Krogh wrote:

> Hi all. I have the following schema:
>
> CREATE TABLE test (
>     id integer NOT NULL,
>     field character varying NOT NULL,
>     value character varying NOT NULL
> );
>
> ALTER TABLE ONLY test
>     ADD CONSTRAINT test_id_key UNIQUE (id, field, value);
>
> CREATE INDEX test_like_idx ON test USING btree (id, field, value
> varchar_pattern_ops);
>
> Using INTERSECT I want to retrieve the rows matching (pseudo-code) "firstname
> LIKE ('andrea%' OR 'jose%') AND lastname LIKE 'kro%'"
>
> on=> SELECT t.id from test t WHERE t.field = 'firstname' AND t.value
> LIKE 'andrea%'
> INTERSECT SELECT t.id FROM test t WHERE t.field = 'firstname' AND t.value
> LIKE 'jose%'
> INTERSECT SELECT t.id FROM test t WHERE t.field = 'lastname'  AND t.value
> LIKE 'kro%';

Do you want something with only a firstname of jose or a firstname of jose
and something other than andrea (and no others) to match or not? I'd read
the pseudo-code to say yes, but AFAICT the query says no.

In general, some form of self-join would probably work, but the details
depend on exactly what should be returned.



view thread (6+ messages)  latest in thread

Message-ID: <20070731140503.F67596@megazone.bigpanda.com>
Permalink:  ../20070731140503.F67596@megazone.bigpanda.com/
Also on:    postgresql.org/message-id/20070731140503.F67596@megazone.bigpanda.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: sszabo@megazone.bigpanda.com, andreak@officenet.no
  Subject: Re: Alternative to INTERSECT
  In-Reply-To: <20070731140503.F67596@megazone.bigpanda.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