Re: Enforcing Join condition

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Enforcing Join condition
Date: 2007-11-15 14:47:22
Message-ID: 20071115144721.GD1955@frubble.xen.chris-lamb.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Nov 15, 2007 at 07:46:46PM +0530, ??????????????????????????? ?????? wrote:
> On Nov 15, 2007 5:52 PM, Sam Mason <sam(at)samason(dot)me(dot)uk> wrote:
> > What I tend to do here, is something like:
> >
> > CREATE TABLE test (
> > type INTEGER,
> > ref1 INTEGER REFERENCES table1 CHECK ((type = 1) = (ref1 IS NOT NULL)),
> > ref2 INTEGER REFERENCES table2 CHECK ((type = 2) = (ref2 IS NOT NULL)),
> > ref3 INTEGER REFERENCES table3 CHECK ((type = 3) = (ref3 IS NOT NULL))
> > );
>
> Thanks for sharing. Will try it. But, we have more than 10 types in
> one table. Will be tough to handle.

As Albe suggested, a view is about all that's going to help the poor
people who work with this. When I do this sort of thing, I tend to
find that there are very few queries that actually need everything all
together in one place. It's generally that (using the naming above)
that you'd do a query on "table1", "test" and something that references
"test". Queries that reference "test", "table1" and "table2" are
reasonably rare. Of course, it could be that I was just lucky here.

Sam

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sam Mason 2007-11-15 14:49:38 Re: Chunk Delete
Previous Message Andrew Sullivan 2007-11-15 14:43:52 Re: Chunk Delete