Re: PGSQL-to-MYSQL Migration: Error in a 'simple' inner join query - Mailing list pgsql-general

From Jeff Davis
Subject Re: PGSQL-to-MYSQL Migration: Error in a 'simple' inner join query
Date
Msg-id 1241463944.19563.19.camel@monkey-cat.sm.truviso.com
Whole thread Raw
In response to Re: PGSQL-to-MYSQL Migration: Error in a 'simple' inner join query  (Andy Colson <andy@squeakycode.net>)
Responses Re: PGSQL-to-MYSQL Migration: Error in a 'simple' inner join query
List pgsql-general
On Mon, 2009-05-04 at 12:30 -0500, Andy Colson wrote:
> Yes, that query works in mysql, but only in mysql... and probably not in
> any other db anywhere.  It is not standard sql.  My guess is that mysql
> is "helping" you out by adding the customer.name for you... but maybe
> not?  Maybe its returning something else?  Too bad it lets you write
> confusing questions.

Section 4.18 of SQL200n, "Functional Dependencies", shows some
interesting ways that the DBMS can make the proper inferences (I think
this is an optional feature, so I don't think PostgreSQL violates the
standard here).

I'm not sure if what DaNieL is asking for is actually covered by this
feature, because it would need to infer the function dependencies:

orders.id -> orders.code
orders.id -> customer.name

and the second one needs to be inferred through a couple steps, and that
may be more sophisticated than what the standard asks for. It can be
done though, because:

orders.id -> orders.id_customer (implied by key on orders.id)
orders.id_customer = customer.id (from join condition)
customer.id -> customer.name (implied by key on customer.id)

Therefore:

orders.id -> customer.name

So he's not asking for anything ridiculous, and it looks to me like he's
supported by the standard (although I'm not an expert on the SQL
standard). However, sometimes it's a good idea to be a little more
explicit in the queries, just for the sake of readability.

Regards,
    Jeff Davis


pgsql-general by date:

Previous
From: Scott Marlowe
Date:
Subject: Re: PGSQL-to-MYSQL Migration: Error in a 'simple' inner join query
Next
From: Tom Lane
Date:
Subject: Re: PGSQL-to-MYSQL Migration: Error in a 'simple' inner join query