Re: : Re: A strange problem

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Tang Tim Hei <timheit(at)netvigator(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: : Re: A strange problem
Date: 2005-08-28 15:11:39
Message-ID: 20050828080419.A27357@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-08-28 15:50:29 Re: About "ERROR: must be *superuser* to COPY to or from a file"
Previous Message Ragnar Hafstað 2005-08-28 14:38:51 Re: : Re: A strange problem