Re: Examples of SQL anomalies?
From: -CELKO- <jcelko212_at_earthlink.net>
Date: Mon, 30 Jun 2008 09:08:36 -0700 (PDT)
Message-ID: <2871ffa7-4243-49b7-9122-e4e5b2c27443_at_a1g2000hsb.googlegroups.com>
Date: Mon, 30 Jun 2008 09:08:36 -0700 (PDT)
Message-ID: <2871ffa7-4243-49b7-9122-e4e5b2c27443_at_a1g2000hsb.googlegroups.com>
>> MIN, MAX and AVG are meaningless when applied to an empty bag, but it seems to me that COUNT should always return 0 when the bag is empty, <<
Which COUNT?; we have two different functions in SQL that look too much alike:
You can fake it with a little code:
CASE WHEN COUNT(*) = COUNT(<exp>) --no nulls in set
THEN SUM(<exp>) -- usual behavior ELSE NULL END -- weird behavior
SQL requires a warning be issued when a NULL is dropped from an aggregate result. You can test for it in your code. The bad news is that when you use a cursor, when that warning comes is implementation defined. It can be done at DECLARE CURSOR, OPEN, the first FETCH or the FETCH that gets the grouping with the NULL dropped from it. Received on Mon Jun 30 2008 - 18:08:36 CEST