Re: BUG #4465: GROUP BY is not to SQL standard

Lists: pgsql-bugs
From: "Tony Marston" <tony(at)marston-home(dot)demon(dot)co(dot)uk>
To: "'Peter Eisentraut'" <peter_e(at)gmx(dot)net>
Cc: <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #4465: GROUP BY is not to SQL standard
Date: 2008-10-14 23:54:16
Message-ID: D7E66A57DD2D4E4D991FE05A476D1AA5@ajmnotebook
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

I think your definition of "Feature T301 Functional Dependencies" is
extremely questionable. A functional dependency in relational theory
automatically exists where a non-key column on a table is functionally
dependent on the key of that table. It is not something that can be turned
on or off with code, it is built into the design of the table, so it is
erroneous to say that "Postgresql does not support functional dependencies".
If you support both key and non-key columns on a table then you support
functional dependencies whether you like it or not.

As for your statement that PostgreSQL has never claimed that it is fully
SQL-compliant, every time I have posted a message to a PG newsgroup and
compared it with MySQL the immediate response which I receive has always
been along the lines of "don't compare PG with MySQL as that is a toy
database that does not follow the standards". As soon as I point out an SQL
standard that you DON'T follow I get a barrage of weasel words and pathetic
excuses.

Tony Marston

http://www.tonymarston.net
http://www.radicore.org

> -----Original Message-----
> From: Peter Eisentraut [mailto:peter_e(at)gmx(dot)net]
> Sent: 14 October 2008 20:17
> To: Tony Marston
> Subject: Re: [BUGS] BUG #4465: GROUP BY is not to SQL standard
>
>
> Tony Marston wrote:
> > I am using document WG3:HBA-003 H2-2003-305 dated August 2003.
> >
> > Section 7.9 - 7 of the SQL-1992 standard states:
> >
> > "If T is a grouped table, then each <column reference> in
> each <value
> > expression> that references a column of T shall reference a
> grouping
> > expression> column
> > or be specified within a <set function specification>."
> >
> > Section 7.12 - 15 of the SQL-2003
> >
> > "If T is a grouped table, then let G be the set of grouping
> columns of
> > T. In each <value expression> contained in <select list>,
> each column
> > reference that references a column of T shall reference
> some column C
> > that is functionally dependent on G or shall be contained in an
> > aggregated argument of a <set function specification> whose
> > aggregation query is QS."
> >
> > This means that it is no longer necessary for every column in the
> > SELECT list to be specified in the GROUP BY clause. It is
> permissible
> > to leave out any column which is functionally dependent on
> any column
> > in the GROUP BY clause. As any non-key column on a table is
> > functionally dependent on the table key then provided that
> the GROUP
> > BY clause contains the table key it is not necessary to specify any
> > non-key columns from that table.
>
> That assessment is correct, but later Section 7.12
> Conformance rule 3 says:
>
> "3) Without Feature T301, "Functional dependencies", in
> conforming SQL
> language, if T is a grouped table, then in each <value expression>
> contained in the <select list>, each <column reference> that
> references
> a column of T shall reference a grouping column or be specified in an
> aggregated argument of a <set function specification>."
>
> This specialized 7.12 GR 15 to allow only column references
> of directly
> grouped columns. In other words, SQL implementations have an
> option of
> supporting a simpler and a more sophisticated behavior,
> distinguished by
> feature T301. Since PostgreSQL does not support T301, we follow the
> specification of 7.12 CR 3. This is perfectly permissible within the
> SQL standard.
>
> > Postgresql still insists on enforcing the outdated 1992 standard,
> > therefore it is wrong to claim that it is SQL-compliant.
> That is why I
> > am reporting it as a bug.
>
> FWIW, PostgreSQL has never claimed that it is fully SQL-compliant.
>
>


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tony Marston <tony(at)marston-home(dot)demon(dot)co(dot)uk>
Cc: "'Peter Eisentraut'" <peter_e(at)gmx(dot)net>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #4465: GROUP BY is not to SQL standard
Date: 2008-10-15 00:28:42
Message-ID: 200810150028.m9F0Sgm05501@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Tony Marston wrote:
> I think your definition of "Feature T301 Functional Dependencies" is
> extremely questionable. A functional dependency in relational theory
> automatically exists where a non-key column on a table is functionally
> dependent on the key of that table. It is not something that can be turned
> on or off with code, it is built into the design of the table, so it is
> erroneous to say that "Postgresql does not support functional dependencies".
> If you support both key and non-key columns on a table then you support
> functional dependencies whether you like it or not.
>
> As for your statement that PostgreSQL has never claimed that it is fully
> SQL-compliant, every time I have posted a message to a PG newsgroup and
> compared it with MySQL the immediate response which I receive has always
> been along the lines of "don't compare PG with MySQL as that is a toy
> database that does not follow the standards". As soon as I point out an SQL
> standard that you DON'T follow I get a barrage of weasel words and pathetic
> excuses.

The issue is that Postgres is _more_ standards-compliant than MySQL, but
Postgres is not 100% compliant either. Is any database system 100%
compliant?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Tony Marston <tony(at)marston-home(dot)demon(dot)co(dot)uk>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #4465: GROUP BY is not to SQL standard
Date: 2008-10-15 00:30:55
Message-ID: 48F539BF.6020403@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Tony Marston wrote:
> I think your definition of "Feature T301 Functional Dependencies" is
> extremely questionable. A functional dependency in relational theory
> automatically exists where a non-key column on a table is functionally
> dependent on the key of that table. It is not something that can be turned
> on or off with code, it is built into the design of the table, so it is
> erroneous to say that "Postgresql does not support functional dependencies".
> If you support both key and non-key columns on a table then you support
> functional dependencies whether you like it or not.

I think you misunderstand what "Features" in the SQL standard mean.
Surely a relational database system supports some kind of functional
dependency system, and there is a common definition for that in the
computer science literature (and there is yet another one in the SQL
standard, part 2, clause 4.18). But in the SQL standard, features
contain conformance claims. Your product can either conform to SQL:2003
with T301, in which case it should behave as in 7.12 GR 15, or it can
conform to SQL:2003 without T301, in which case it should behave as in
7.12 CR 3. Both of these can claim to conform to SQL, if they declare
the details correctly. The fact that T301 is labeled "Functional
dependencies" is an informative label for what the feature generally
tries to achieve, but it is not a normative description of the feature
itself, since that is given elsewhere in the standard.

Since PostgreSQL is documented not to support feature T301, we apply
7.12 CR 3, and no one has so far disputed that we do so incorrectly.

Now you might say, then PostgreSQL is not a real relational database
system. But I believe it is widely understood that no SQL
implementation implements relational theory correctly. That's a whole
different can of worms.

> As for your statement that PostgreSQL has never claimed that it is fully
> SQL-compliant, every time I have posted a message to a PG newsgroup and
> compared it with MySQL the immediate response which I receive has always
> been along the lines of "don't compare PG with MySQL as that is a toy
> database that does not follow the standards". As soon as I point out an SQL
> standard that you DON'T follow I get a barrage of weasel words and pathetic
> excuses.

The level of SQL conformance as evaluated by the PostgreSQL developers
can be found in the documentation. If MySQL has a similar document, you
can draw your own comparisons. I know of no such document, but I would
guess that MySQL is less conforming than PostgreSQL.

You should, however, not mistake the chatter of the PostgrSQL newsgroup
mob as facts, authorative statements, or representative of the opinions
of the project leadership. We cannot choose the people our newsgroups
attract.

I am sorry that you interpret my attempts to explain my reading of the
SQL standards to you as weasel words and pathetic excuses. If you
cannot restrict your comments to rational arguments and have to resort
to name-calling, then I should probably not waste any more time
discussing with you.


From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Tony Marston" <tony(at)marston-home(dot)demon(dot)co(dot)uk>
Cc: "'Peter Eisentraut'" <peter_e(at)gmx(dot)net>, <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #4465: GROUP BY is not to SQL standard
Date: 2008-10-15 01:56:51
Message-ID: 87fxmyboyk.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

"Tony Marston" <tony(at)marston-home(dot)demon(dot)co(dot)uk> writes:

> I think your definition of "Feature T301 Functional Dependencies" is
> extremely questionable. ... If you support both key and non-key columns on a
> table then you support functional dependencies whether you like it or not.

An ISO/IEC 9075 conformant implementation must list in its documentation which
optional features it claims to support. Postgres does so at:

http://www.postgresql.org/docs/8.3/static/features.html

In particular note that T301 is listed partway down this list:

http://www.postgresql.org/docs/8.3/static/unsupported-features-sql-standard.html

> As soon as I point out an SQL standard that you DON'T follow I get a barrage
> of weasel words and pathetic excuses.

Well then.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's 24x7 Postgres support!


From: "Tony Marston" <tony(at)marston-home(dot)demon(dot)co(dot)uk>
To: "'Gregory Stark'" <stark(at)enterprisedb(dot)com>
Cc: <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #4465: GROUP BY is not to SQL standard
Date: 2008-10-15 09:41:19
Message-ID: 2225B537D84946F2A1FD3EF7840C4BD4@ajmnotebook
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

You are still missing the point - "functional dependencies" is not a
separate module that can be turned on or off with code, they are inherent in
the database design. According to relational theory any non-key field on a
table is functionally dependent of the key of that table, so if you support
both key and non-key fields on a table then you automatically support
functional dependencies. How can you possibly say otherwise?

Where does it describe in the SQL standards EXACTLY what the term
"functional dependencies" means? Is it the same as in relational theory, or
is it something different?

Tony Marston

http://www.tonymarston.net
http://www.radicore.org

> -----Original Message-----
> From: Greg Stark [mailto:greg(dot)stark(at)enterprisedb(dot)com] On
> Behalf Of Gregory Stark
> Sent: 15 October 2008 02:57
> To: Tony Marston
> Cc: 'Peter Eisentraut'; pgsql-bugs(at)postgresql(dot)org
> Subject: Re: BUG #4465: GROUP BY is not to SQL standard
>
>
> "Tony Marston" <tony(at)marston-home(dot)demon(dot)co(dot)uk> writes:
>
> > I think your definition of "Feature T301 Functional
> Dependencies" is
> > extremely questionable. ... If you support both key and non-key
> > columns on a table then you support functional dependencies whether
> > you like it or not.
>
> An ISO/IEC 9075 conformant implementation must list in its
> documentation which optional features it claims to support.
> Postgres does so at:
>
> http://www.postgresql.org/docs/8.3/static/features.html
>
> In particular note that T301 is listed partway down this list:
>
> http://www.postgresql.org/docs/8.3/static/unsupported-features
-sql-standard.html

> As soon as I point out an SQL standard that you DON'T follow I get a
> barrage of weasel words and pathetic excuses.

Well then.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's 24x7 Postgres support!


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Tony Marston <tony(at)marston-home(dot)demon(dot)co(dot)uk>
Cc: 'Gregory Stark' <stark(at)enterprisedb(dot)com>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #4465: GROUP BY is not to SQL standard
Date: 2008-10-15 10:53:26
Message-ID: 48F5CBA6.4020805@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Tony Marston wrote:
> You are still missing the point - "functional dependencies" is not a
> separate module that can be turned on or off with code,

It is in the SQL standard.

> they are inherent in
> the database design. According to relational theory any non-key field on a
> table is functionally dependent of the key of that table, so if you support
> both key and non-key fields on a table then you automatically support
> functional dependencies. How can you possibly say otherwise?

Again, you are confusing the SQL standard with relational theory, and an
SQL standard conformance feature name with the computer science
interpretation of that name. I suggest you read Part 1 "Framework" of
SQL 2003 which explains how SQL conformance works.

> Where does it describe in the SQL standards EXACTLY what the term
> "functional dependencies" means? Is it the same as in relational theory, or
> is it something different?

We are talking about feature T301, which is defined by the Conformance
rules that mention it. That is all that matters. It does not matter
what the name of that feature is.


From: "Tony Marston" <tony(at)marston-home(dot)demon(dot)co(dot)uk>
To: "'Peter Eisentraut'" <peter_e(at)gmx(dot)net>
Cc: <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #4465: GROUP BY is not to SQL standard
Date: 2008-10-15 12:47:40
Message-ID: 9330DA53AEEF4D9D974E7BE71C25B844@ajmnotebook
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Support for functional dependencies is not a feature that can be turned off
in any database engine. Dependencies, whether they are functional,
transitive, multi-valued or join dependencies, are inherent in the database
design. It is therefore nonsense to say that support for functional
dependencies is optional.

Saying that the SQL standard and Relational Theory are unconnected is
complete misdirection. The SQL standard is surely there to define how
Relational Theory can/should be implemented. A database cannot be classed as
"relational" if it does not support standard SQL, therefore the two must go
hand in hand.

The simple fact is that it is only in the 1992 standard that it states that
ALL columns in the SELECT clause must be identified in the GROUP BY clause.
In all subsequent standards it has been permissible to omit any column from
the GROUP BY clause if it is functionally dependent on any other column in
the GROUP BY clause. All you can do is point to paragraphs which are NOT
contained in the definition of the GROUP BY clause and say "this is our get
out". Now you wonder why I refer to your arguments as "weasel words".

Tony Marston

http://www.tonymarston.net
http://www.radicore.org

> -----Original Message-----
> From: Peter Eisentraut [mailto:peter_e(at)gmx(dot)net]
> Sent: 15 October 2008 11:53
> To: Tony Marston
> Cc: 'Gregory Stark'; pgsql-bugs(at)postgresql(dot)org
> Subject: Re: [BUGS] BUG #4465: GROUP BY is not to SQL standard
>
>
> Tony Marston wrote:
> > You are still missing the point - "functional dependencies"
> is not a
> > separate module that can be turned on or off with code,
>
> It is in the SQL standard.
>
> > they are inherent in
> > the database design. According to relational theory any
> non-key field
> > on a table is functionally dependent of the key of that
> table, so if
> > you support both key and non-key fields on a table then you
> > automatically support functional dependencies. How can you possibly
> > say otherwise?
>
> Again, you are confusing the SQL standard with relational
> theory, and an
> SQL standard conformance feature name with the computer science
> interpretation of that name. I suggest you read Part 1
> "Framework" of
> SQL 2003 which explains how SQL conformance works.
>
> > Where does it describe in the SQL standards EXACTLY what the term
> > "functional dependencies" means? Is it the same as in relational
> > theory, or is it something different?
>
> We are talking about feature T301, which is defined by the
> Conformance
> rules that mention it. That is all that matters. It does not matter
> what the name of that feature is.
>
>


From: Andrew Sullivan <ajs(at)commandprompt(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #4465: GROUP BY is not to SQL standard
Date: 2008-10-15 13:51:20
Message-ID: 20081015135120.GB56739@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

On Wed, Oct 15, 2008 at 01:47:40PM +0100, Tony Marston wrote:

> Support for functional dependencies is not a feature that can be
> turned off in any database engine.

Repeating the same premise over and over again does not constitute an
argument. In this case, you appear to be begging the question. I
think you have your answer, even if you don't like it.

A
--
Andrew Sullivan
ajs(at)commandprompt(dot)com
+1 503 667 4564 x104
http://www.commandprompt.com/


From: David Fetter <david(at)fetter(dot)org>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tony Marston <tony(at)marston-home(dot)demon(dot)co(dot)uk>, 'Peter Eisentraut' <peter_e(at)gmx(dot)net>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #4465: GROUP BY is not to SQL standard
Date: 2008-10-15 15:57:14
Message-ID: 20081015155714.GC18271@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

On Tue, Oct 14, 2008 at 08:28:42PM -0400, Bruce Momjian wrote:
> Tony Marston wrote:
> > I think your definition of "Feature T301 Functional Dependencies"
> > is extremely questionable. [et cetæra, ad nauseam]
>
> The issue is that Postgres is _more_ standards-compliant than MySQL,
> but Postgres is not 100% compliant either. Is any database system
> 100% compliant?

No.

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Tony Marston <tony(at)marston-home(dot)demon(dot)co(dot)uk>
Cc: 'Peter Eisentraut' <peter_e(at)gmx(dot)net>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #4465: GROUP BY is not to SQL standard
Date: 2008-10-16 03:45:37
Message-ID: 48F6B8E1.7070200@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

[Note: I'm *not* an expert in the SQL standard, but I might be able to
help clarify a misunderstanding or two in the discussion so far].

Tony Marston wrote:
> Support for functional dependencies is not a feature that can be turned off
> in any database engine. Dependencies, whether they are functional,
> transitive, multi-valued or join dependencies, are inherent in the database
> design.

Well, my understanding is that they're a core part of relational theory,
anyway. This doesn't necessarily make them "inherent in the database
design" - in that AFAIK no computer database implementation fully
implements the correct and complete relational calculus.

In a sense, all relational database implementations can be considered
"incorrect" - they can all produce results that wouldn't be permitted by
a strict relational implementation. On the upside, they actually produce
the results this century, and correctness can still be assured by manual
locking in critical situations.

If there really is a strict and pure relational implementation, I'd be
curious to know about it. Does it work? Does it work in the real world?

> It is therefore nonsense to say that support for functional
> dependencies is optional.

Again, that's true for the theory, but practical implementations may not
achieve theoretical perfection. SQL is a standard describing
requirements and optional features fo a practial implementation of a
relational database engine, not a description of relational theory.

> Saying that the SQL standard and Relational Theory are unconnected is
> complete misdirection. The SQL standard is surely there to define how
> Relational Theory can/should be implemented.

You have used the word "surely" - in this case, as conjecture. People
here have already told you that the SQL standard does NOT describe a
strict implementation of relational theory, and that an SQL-confirming
implementation may lack features like predicate locking, identification
of functional dependencies in result sets, etc.

> A database cannot be classed as
> "relational" if it does not support standard SQL, therefore the two must go
> hand in hand.

Er, no. Support for standard SQL does not imply a strict implementation
of relational theory (ie being "classed as relational"), as the SQL
standard does not actually describe a strict implementation of
relational theory. I don't know enough about the standard to be sure,
but I wouldn't be too surprised if a fully conformant SQL implementation
could *not* strictly implement relational theory.

> The simple fact is that it is only in the 1992 standard that it states that
> ALL columns in the SELECT clause must be identified in the GROUP BY clause.
> In all subsequent standards it has been permissible to omit any column from
> the GROUP BY clause if it is functionally dependent on any other column in
> the GROUP BY clause. All you can do is point to paragraphs which are NOT
> contained in the definition of the GROUP BY clause and say "this is our get
> out". Now you wonder why I refer to your arguments as "weasel words".

What's been said in response to your initial post all looks pretty
reasonable to me, and I see attempts to explain the situation rather
than "weasel".

Standards aren't generally the perfect ideals we might want them to be,
and the SQL standard is full of optional features, practical
compromises, and so on. As Peter Eisentraut explained in reply to your
initial post, PostgreSQL does not support one of the optional features
in the SQL-99/SQL-2003 standard, namely T301, and retains SQL-92
behaviour in this area. That's perfectly acceptable according to the
standard.

The definition of functional dependencies in T301 that you are arguing
about is a definition in the SQL standard that PostgreSQL attempts to
follow, not a definition made up by the PostgreSQL developers. If you
don't like the definition, you'll need to take that up with the SQL
standards body. If it contradicts relational theory, then that's either
a practical compromise or an error made by the SQL standards body.

It would be nice if PostgreSQL did support that feature. However, it can
be compliant with the SQL standard without it, as it's an optional
feature. (In fact I don't know if PostgreSQL *is* fully compliant with
any of the SQL standards, but that's another issue).

Arguably no SQL database should be described as "relational" - but in
practice, SQL describes a good and workable approximation of relational
theory that works in the real world and is useful to describe as
"relational" to distinguish it from other, completely different,
database designs.

--
Craig Ringer