COUNT (DISTINCT (column)) expression regression in H2 1.3.156

907 views
Skip to first unread message

Oleg Alexeyev

unread,
Jun 21, 2011, 11:35:22 AM6/21/11
to H2 Database
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

Thomas Mueller

unread,
Jun 27, 2011, 3:05:31 AM6/27/11
to h2-database
Hi,

This is fixed in version 1.3.156.

Thanks for your help!

Regards,
Thomas

Oleg Alexeyev

unread,
Jun 27, 2011, 7:33:51 AM6/27/11
to H2 Database
Yep, it's fixed in 1.3.157.

Thanks!

--oleg
Reply all
Reply to author
Forward
0 new messages