Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 63078 invoked from network); 20 Jul 2004 20:29:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 20 Jul 2004 20:29:16 -0000 Received: (qmail 37919 invoked by uid 500); 20 Jul 2004 20:29:15 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 37846 invoked by uid 500); 20 Jul 2004 20:29:15 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "OJB Developers List" Reply-To: "OJB Developers List" Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 37832 invoked by uid 99); 20 Jul 2004 20:29:15 -0000 X-ASF-Spam-Status: No, hits=1.4 required=10.0 tests=SUBJ_HAS_SPACES X-Spam-Check-By: apache.org Received: from [165.98.147.95] (HELO ags01.agsoftware.dnsalias.com) (165.98.147.95) by apache.org (qpsmtpd/0.27.1) with ESMTP; Tue, 20 Jul 2004 13:29:12 -0700 Received: from ags01.agsoftware.dnsalias.com (localhost.localdomain [127.0.0.1]) by ags01.agsoftware.dnsalias.com (8.12.10/8.12.10) with ESMTP id i6KKT054020301 for ; Tue, 20 Jul 2004 14:29:00 -0600 Received: (from apache@localhost) by ags01.agsoftware.dnsalias.com (8.12.10/8.12.10/Submit) id i6KKT0Ie020299; Tue, 20 Jul 2004 14:29:00 -0600 X-Authentication-Warning: ags01.agsoftware.dnsalias.com: apache set sender to cchavez@agssa.net using -f Received: from 10.0.0.1 (SquirrelMail authenticated user cchavez); by ags01.agsoftware.dnsalias.com with HTTP; Tue, 20 Jul 2004 14:29:00 -0600 (CST) Message-ID: <54721.10.0.0.1.1090355340.squirrel@10.0.0.1> Date: Tue, 20 Jul 2004 14:29:00 -0600 (CST) Subject: Re: [ReportQueryByCriteria] - Error in SQL generated when using GROUP BY sentence ? From: Carlos =?iso-8859-1?Q?Ch=E1vez?= To: "OJB Developers List" Reply-To: cchavez@agssa.net User-Agent: SquirrelMail/1.4.3a-0.f1.1 X-Mailer: SquirrelMail/1.4.3a-0.f1.1 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Hi Jakob. Jakob Braeuchi Escribio :-) > hi carlos, > > i have a solution that works for hsqldb and mysql. > > if the orderBy- or groupByFiled is found in the list of selected fields > it's > index is used otherwise it's name is used: > > SELECT A0.ID,A0.FIRSTNAME,count(*) FROM PERSON A0 WHERE A0.FIRSTNAME LIKE > ? > GROUP BY 1,2 This do not work in postgresql > > SELECT max(A0.ID) FROM PERSON A0 GROUP BY A0.LASTNAME,A0.FIRSTNAME > > could you please verify whether group by index also is working for > postgresql. group by index do not work in postgresql. work fine for order by but not for group by. Cheers, Carlos Ch�vez. > > jakob > > Carlos Ch�vez schrieb: > >> Hi jakob. >> >> Jakob Braeuchi Escribio :-) >> >>>hi carlos, >>> >>>this is caused by the call to ensureColumns in >>>SqlSelectStatement#getStatement >>> >>>... >>> groupByFields = query.getGroupBy(); >>> if (groupByFields != null && !groupByFields.isEmpty()) >>> { >>>// ensureColumns(groupByFields, columnList, stmt); >>> } >>>... >>> >>>if you comment this line (nr. 221) the sql should look ok. >>> >>>imo we could drop this call completely, but before i do so, i'll have to >>>run all >>>the testcases. >>>we use the same procedure for orderby as well, because we >>>order >>>by column-position and not by column-name. may be we could drop this as >>>well ? >> >> >> i think we can drop this in both case. >> >> if the particular implementation of a database need this, we can do >> this >> for the database only. >> >> In case of postgresql i test this and we do not need what the column >> in the "group by" an "order by" are part of the columns of the result. >> >> Cheers >> Carlos Ch�vez. >> >> >>>hth >>>jakob >>> >>>Carlos Ch�vez schrieb: >>> >>> >>>> Hi to all, >>>> >>>> I write the next code : >>>> >>>> Criteria criterio = new Criteria(); >>>> criterio.addEqualTo("fam_id", famId); >>>> criterio.addEqualTo("prod_id", prodId); >>>> ReportQueryByCriteria subQuery = new >>>>ReportQueryByCriteria(Detallecompra.class, criterio); >>>> subQuery.setAttributes(new String[] { "max(facc_id)" }); >>>> subQuery.addGroupBy(new String[] { "fam_id", "prod_id" }); >>>> >>>> if the SQL generated above i want to use like a subquery, >>>> OJB send me the next message of error: >>>> >>>>org.apache.ojb.broker.PersistenceBrokerSQLException: >>>>java.sql.SQLException: ERROR: Subselect must have only one field >>>> >>>> Then, I was asking myself why this happened, if only set one >>>> attribute: >>>> subQuery.setAttributes(new String[] { "max(facc_id)" }); >>>> >>>> I found that the attributes of GROUP BY are added to sentence SQL, >>>> although these do not appear in the result >>>> >>>> the SQL generated is: >>>> SELECT max(A0.FACC_ID),A0.FAM_ID as ojb_col_1,A0.PROD_ID as ojb_col_2 >>>> FROM DETALLECOMPRA A0 WHERE (A0.FAM_ID = ?) AND A0.PROD_ID = ? >>>> GROUP BY A0.FAM_ID,A0.PROD_ID >>>> >>>> but i think the correct is : >>>> SELECT max(A0.FACC_ID) >>>> FROM DETALLECOMPRA A0 WHERE (A0.FAM_ID = ?) AND A0.PROD_ID = ? >>>> GROUP BY A0.FAM_ID,A0.PROD_ID >>>> >>>> because the attributes A0.FAM_ID,A0.PROD_ID are not indicated in the >>>> sentences: subQuery.setAttributes(new String[] { "max(facc_id)" }); >>>> there are part of the GROUP BY but not the setAttributes sentences >>>> >>>> there is some reason for this behavior or this is an error ? >>>> >>>> IMO this is an error. >>>> >>>> i am using ojb 1.0.0. >>>> >>>> Cheers, >>>> >>> >>>--------------------------------------------------------------------- >>>To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org >>>For additional commands, e-mail: ojb-dev-help@db.apache.org >>> >> >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org > For additional commands, e-mail: ojb-dev-help@db.apache.org > -- Carlos Ch�vez --------------------------------------------------------------------- To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For additional commands, e-mail: ojb-dev-help@db.apache.org