Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 111279FBB0E for ; Wed, 25 Jul 2007 02:21:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 79331-02 for ; Wed, 25 Jul 2007 02:21:20 -0300 (ADT) X-Greylist: delayed 06:04:25.49335 by SQLgrey-1.7.5 Received: from rfallback.ya.com (rfallback.ya.com [62.151.4.18]) by postgresql.org (Postfix) with ESMTP id 205DF9FBABD for ; Wed, 25 Jul 2007 02:21:19 -0300 (ADT) Received: from [192.168.1.154] (helo=smtpauth.ya.com) by rfallback.ya.com with esmtp id 1IDTca-0002s7-00 for pgsql-jdbc@postgresql.org; Wed, 25 Jul 2007 01:16:52 +0200 Received: from [80.30.201.98] (helo=[80.30.201.98]) by smtpauth.ya.com with asmtp id 1IDTcW-0001RM-00 for pgsql-jdbc@postgresql.org; Wed, 25 Jul 2007 01:16:48 +0200 Message-ID: <46A6891E.7090809@ya.com> Date: Wed, 25 Jul 2007 01:19:58 +0200 From: Marcos Truchado User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070301 SUSE/1.0.9-1.1 SeaMonkey/1.0.9 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: problem with date_trunc and jdbc Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200707/113 X-Sequence-Number: 17287 Hello people, I have an strange problem here. Suppose I have a table mytable with a column mydate of type date. if I launch this SQL directly with psql: SELECT date_trunc('month', mydate)::date FROM mytable WHERE mytable.mydate BETWEEN '2000-07-25 +02:00' AND '2004-07-25 +02:00' GROUP BY date_trunc('month', mydate); I obtaint the months/years in where exists any record in this table with a date stored in mydate that uses this month/year, all between 2 dates This sql works ok under psql. But if I try to execute it with jdbc: String sql = "SELECT date_trunc('month', mydate)::date FROM mytable WHERE mytable.mydate BETWEEN ? AND ? GROUP BY date_trunc('month', mydate)"; PreparedStatement pstmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); Calendar calendar = Calendar.getInstance(); //initial date, suppose f_ini has the correct date calendar.setTime(f_ini); pstmt.setDate(1, new java.sql.Date(calendar.getTimeInMillis())); //end date, suppose f_end has the correct date calendar.setTime(f_end); pstmt.setDate(2, new java.sql.Date(calendar.getTimeInMillis())); pstmt.executeQuery(); The code works ok, but when it reaches to executeQuery() statement it fails with message "mytable.mydate must be used in group by clause or in aggregate function" Where is the fault?. I'm using postgresql 8.1.9 and jdbc driver 8.1 build 409 JDBC3 Best regards