Re: Group by clause problem with postgresql jdbc 9.0-801
От | Seckin Pulatkan |
---|---|
Тема | Re: Group by clause problem with postgresql jdbc 9.0-801 |
Дата | |
Msg-id | BAY162-ds607D3F9056B0A431E8D2FCE1E0@phx.gbl обсуждение исходный текст |
Ответ на | Re: Group by clause problem with postgresql jdbc 9.0-801 (Simon Riggs <simon@2ndQuadrant.com>) |
Список | pgsql-jdbc |
I converted my code to native query version and then query worked successfully. Thank you for pointing out the problem and your suggestions. Kind Regards, Seckin -----Oorspronkelijk bericht----- Van: Simon Riggs [mailto:simon@2ndQuadrant.com] Verzonden: 08 September 2011 08:01 Aan: Maciek Sakrejda CC: Dave Cramer; Seckin Pulatkan; pgsql-jdbc Onderwerp: Re: [JDBC] Group by clause problem with postgresql jdbc 9.0-801 On Wed, Sep 7, 2011 at 10:55 PM, Maciek Sakrejda <msakrejda@truviso.com> wrote: > Could this be the difference between > > cqdb=# prepare foo(int, int) as select x / $1 from generate_series(1,10) x > group by x / $2; execute foo(3,3); > ERROR: column "x.x" must appear in the GROUP BY clause or be used in an > aggregate function > ERROR: prepared statement "foo" does not exist > > and > > cqdb=# select x / 3 from generate_series(1,10) x group by x / 3; > ?column? > ---------- > 2 > 0 > 3 > 1 > (4 rows) > > ? > > This could be the case if Navicat is inlining the parameters. Unfortunately, > I can't think of a good suggestion for a fix if this is indeed the case > (except that the generated queries should group by the columns of interest, > rather than repeating the expressions, but that's probably not an easy > fix)... Yes, agreed. The server error message is clear from the messages shown, nothing more needed. The problem is that date_part(?, age(t1.create_timestamp)) in the SELECT caluse does not match date_part(?, age(t1.create_timestamp)) in the GROUP BY clause, because the presence of parameter markers means that they are potentially different expressions. Try re-writing the query like this: * In SELECT clause write date_part(?, age(t1.create_timestamp)) AS expression1 * In GROUP BY clause write expression1 instead of date_part(?, age(t1.create_timestamp)) The SQL parser will then recognise the GROUP BY correctly. I think we could regard this as a JDBC annoyance, but we're not parsing the SQL at that point so it's got no way to know the two parameter markers ("?") would be the same. I'm sure the same problem would exist in JDBC with other RDBMS also, since its a problem caused by unnamed parameter markers. -- Simon Riggs http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services
В списке pgsql-jdbc по дате отправления: