Hi,

It looks like there is a regression on handling COUNT (DISTINCT
(column)) expression in H2 1.3.156.
Here is a sample program:
----------8<----------
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;


public class CountTest
{
        public static void main (String[] args) throws Exception
        {
                Class.forName ("org.h2.Driver");
                Connection connection = DriverManager.getConnection ("jdbc:h2:./
test");

                Statement init = connection.createStatement ();
                init.execute ("CREATE TABLE packages (id BIGINT NOT NULL 
IDENTITY,
PRIMARY KEY (id))");
                init.execute ("CREATE TABLE package_entries (package_id BIGINT 
NOT
NULL, name VARCHAR_IGNORECASE NOT NULL, PRIMARY KEY (package_id,
name), FOREIGN KEY (package_id) REFERENCES packages (id) ON DELETE
CASCADE)");
                init.execute ("INSERT INTO packages (id) VALUES (1)");
                init.close ();

                PreparedStatement insert = connection.prepareStatement ("INSERT 
INTO
package_entries (package_id, name) VALUES (1, ?)");
                for (int i = 0; i < 10; i++)
                {
                        insert.setString (1, Integer.toString (i));
                        insert.execute ();
                }
                insert.close ();

                Statement select = connection.createStatement ();
                select.execute ("SELECT COUNT(DISTINCT(package_id)) FROM
package_entries");
                ResultSet resultSet = select.getResultSet ();
                resultSet.next ();
                System.out.println (resultSet.getLong (1));
                resultSet.close ();
                select.close ();

                select = connection.createStatement ();
                select.execute ("SELECT COUNT(*) FROM (SELECT DISTINCT 
package_id
FROM package_entries)");
                resultSet = select.getResultSet ();
                resultSet.next ();
                System.out.println (resultSet.getLong (1));
                resultSet.close ();
                select.close ();

                connection.close ();
        }
}
----------8<----------

With H2 1.3.155 the output is:
1
1

With 1.3.156 the output is:
10
1

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to