Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TaGCy-00029p-F9 for pgsql-jdbc@postgresql.org; Mon, 19 Nov 2012 01:31:32 +0000 Received: from outmail148154.authsmtp.co.uk ([62.13.148.154]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TaGCv-00064X-2S for pgsql-jdbc@postgresql.org; Mon, 19 Nov 2012 01:31:31 +0000 Received: from mail-c232.authsmtp.com (mail-c232.authsmtp.com [62.13.128.232]) by punt6.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id qAJ1VSpw028866; Mon, 19 Nov 2012 01:31:28 GMT Received: from ayaki.localdomain (office1.postnewspapers.com.au [150.101.171.128]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/) with ESMTP id qAJ1VIt3036946 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Mon, 19 Nov 2012 01:31:22 GMT Message-ID: <50A98BE5.5010600@2ndQuadrant.com> Date: Mon, 19 Nov 2012 09:31:17 +0800 From: Craig Ringer Organization: 2nd Quadrant User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121029 Thunderbird/16.0.2 MIME-Version: 1.0 To: =?ISO-8859-1?Q?Zsolt_K=FAti?= CC: pgsql-jdbc@postgresql.org Subject: Re: The column name was not found in this ResultSet References: <20121114114240.3a649bb7@kuti-zsolt.intranet.prolan.hu> In-Reply-To: <20121114114240.3a649bb7@kuti-zsolt.intranet.prolan.hu> X-Enigmail-Version: 1.4.5 Content-Type: text/plain; charset=ISO-8859-1 X-Server-Quench: d3f75d86-31e8-11e2-b10b-0025903375e2 X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCdxZQATClZeVg0b BQteCiN5VAwpPBRK HVkIKg5MJUcNSQVJ NksadBtFaQxbY1ZH HGQLWlZEUFx7WmJ/ aQkfbABdfEtOXhtr V0lXQ1BaCwdtAxke B1BfI2NzEXwCe35z Y09mWD5TVUF/OxJ+ FElRQWUAeGRhPWgC UUENdR4GcQMYYx9F aFV2VHAOZmBSZDQC El17DBIdFx5qYBhV T0kGKlYPREBDGDc5 SlhWFjIrSwUaTj57 KRs6YlAbAUAdekQ0 eUchWElQCRIJFwlC JExRaMDP X-Authentic-SMTP: 61633235383639.1019:706 X-AuthFastPath: 0 (Was 255) X-AuthSMTP-Origin: 150.101.171.128/2525 X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system. Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by punt6.authsmtp.com id qAJ1VSpw028866 X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201211/83 X-Sequence-Number: 23550 On 11/14/2012 06:42 PM, Zsolt K=FAti wrote: > Hello, > > In a query like this: > select * form T1 a, T2 b where a.id=3D'xx' and a.id=3Db.id > > calling the result set: > rs.getString("o.id") > > I get: > org.postgresql.util.PSQLException: The column name o.id was not found > in this ResultSet. at > org.postgresql.jdbc2.AbstractJdbc2ResultSet.findColumn(AbstractJdbc2Res= ultSet.java:2562) > at > org.postgresql.jdbc2.AbstractJdbc2ResultSet.getString(AbstractJdbc2Resu= ltSet.java:2405) > at > hu.prolan.emgmt.fre.service.store.impl.OrderStoreImpl.loadOrder(OrderSt= oreImpl.java:236) > > Getting data by index is OK, just as simply using getString('id'). This > nonqualified access however cannot get to the next column with the > same name... > > How can the columns accessed by qualified name? > Is it a bug? I don't think so, but it isn't simple. Consider the following: regress=3D> SELECT a.n, 'somevalue' AS "a.n" FROM (VALUES ('othervalue')) a(n); n | a.n =20 ------------+----------- othervalue | somevalue (1 row) Which of these columns is "a.n" to PgJDBC? The one actually called "a.n" (note the identifier quotes)? Or the one called "n" with table-alias "a"? The JDBC API does not offer us a "ResultSet.getString(String columnname, String schemaname)" that would allow us to disambiguate these cases. So we either have to: (a) Intepret all identifiers passed to get...() functions as if they were PostgreSQL identifier literals, unescaping them and splitting them into schema-part and literal-part; or (b) Just get the first column with the given name and require users to alias column names to disambiguate them. In my opinion (a) would be horrible to use, and it appears to be contrary to the JDBC Resultset spec as well. You'd have to "double quote" every identifier if you wanted to use mixed case or any kind of non-alphanumeric strings, so: rs.getString("B.F. Name") would have to become: rs.getString("\"B.F. Name\"") or users would get syntax errors, identifier parsing errors, or bizarre errors about columns not being found. So (b) is the best compromise, really. Just alias your columns to disambiguate them in the result set by specifying `AS` aliases. --=20 Craig Ringer http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services