Re: sql join question

From: Scott Frankel <leknarf(at)pacbell(dot)net>
To: Ragnar Hafstað <gnari(at)simnet(dot)is>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: sql join question
Date: 2005-03-02 00:51:24
Message-ID: 429dd4c7ee91a1c73aea17c0316ecd0f@pacbell.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Sweet! And not so sweet.

The natural join worked beautifully with my test schema; but it failed
to yield any rows with my real-world schema. I think I've tracked down
why: duplicate column names. i.e.:

-1- these tables yield rows from a NATURAL JOIN query
CREATE TABLE palettes (palette_pkey SERIAL PRIMARY KEY,
palette_name text UNIQUE DEFAULT NULL);

CREATE TABLE tones (tone_pkey SERIAL PRIMARY KEY,
tone_name text UNIQUE DEFAULT NULL,
palette_pkey integer REFERENCES palettes);

-2- these tables yield NO rows from a NATURAL JOIN query
CREATE TABLE palettes (palette_pkey SERIAL PRIMARY KEY,
palette_name text UNIQUE DEFAULT NULL,
qwe text);

CREATE TABLE tones (tone_pkey SERIAL PRIMARY KEY,
tone_name text UNIQUE DEFAULT NULL,
palette_pkey integer REFERENCES palettes,
qwe text);

Are the 'qwe' columns in both tables clobbering each other and
preventing the
join from succeeding? The offending columns are inconsequential for
what I'm
trying to do with this operation. Can they be suppressed from the
query for this
SQL statement to function properly? Or am I SOL?

Thanks again!
Scott

On Mar 1, 2005, at 2:28 PM, Ragnar Hafstað wrote:

> On Tue, 2005-03-01 at 13:42 -0800, Scott Frankel wrote:
>
>> [snip problem]
>
>> Task: find all color names in each of palette1's tones.
>>
>> Can this be done in a single SQL statement?
>
>> [snip table examples]
>
> looks like a job for NATURAL JOIN
>
> test=# select color_name
> from palettes
> natural join tones
> natural join colors
> where palette_name='plt1';
>
> color_name
> ----------------
> rose madder
> crimson
> red ochre
> phthalocyanine
> leaf green
> (5 rows)
>
>
> gnari
>
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 8: explain analyze is your friend
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jonathan Hedstrom 2005-03-02 00:53:58 Re: Trigger email?
Previous Message Tom Lane 2005-03-02 00:38:04 Re: basic temp table question