Re: : Re: A strange problem - Mailing list pgsql-general

From Stephan Szabo
Subject Re: : Re: A strange problem
Date
Msg-id 20050828080419.A27357@megazone.bigpanda.com
Whole thread Raw
In response to Re: : Re: A strange problem  (Tang Tim Hei <timheit@netvigator.com>)
List pgsql-general
On Sun, 28 Aug 2005, Tang Tim Hei wrote:

> > Well, you have to write your queries to do what you want depending on such
> > things.  For example, the above doesn't constrain the join from currency
> > and country and so you get multiple copies of the USD currency info for
> > each country.  If you want to constrain the currency and country
> > information (for example, say A.country=B.id if you had that sort of
> > information) you need to decide what happens if there is no country that
> > matches the country.
>
> Let me explain my point in more detail below:
>
> The following commands are little different from the previous one.
> (1) select A.* from test.currency A, test.price_list B where
> A.curr_cd=B.curr_cd and A.curr_cd='USD'
> (2) select A.* from test.currency A, test.price_list B, test.country C
> where A.curr_cd=B.curr_cd and A.curr_cd='USD'
>
> For command (1), it is ok. The result is what I expect.
> However, for command (2), it has problem. I added the "test.country C"
> to it, here I actually just write a table name to it and no more other
> purpose. However, the result maybe totally different. If the table
> "country" is not empty, the result is just the same as in command (1)
> but if "country" is empty, there are no result row.

Theoretically, it's not the same if country has multiple rows given the
query above.  The second query is simply incorrect if you want one row for
each currency that has a price list and is USD.

> The point is that: even though I add a constraint to a command, if an
> additional empty table is mentioned in the command, the result may be
> different.

Right, the result is different because it's a query with a different
semantic meaning in SQL.

The first query means something like:
 Return currency data for any currency with curr_cd='USD' which has a
price list.

The second query means something like:
 Return a copy of the currency data for any currency with curr_cd='USD'
which has a price list once for each row in country (which implicitly
means no times if there are no rows in country).

If you write the second when you are trying to get the first meaning,
that's an error in whatever is generating the query.

pgsql-general by date:

Previous
From: Ragnar Hafstað
Date:
Subject: Re: : Re: A strange problem
Next
From: Tom Lane
Date:
Subject: Re: About "ERROR: must be *superuser* to COPY to or from a file"