Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 1209E9FA409 for ; Thu, 30 Aug 2007 17:50:54 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 11528-04-2 for ; Thu, 30 Aug 2007 17:50:43 -0300 (ADT) X-Greylist: delayed 00:06:00.276475 by SQLgrey-1.7.5 Received: from pageserv2.de (pageserv2.de [85.10.192.207]) by postgresql.org (Postfix) with ESMTP id 790ED9FA3EC for ; Thu, 30 Aug 2007 17:50:47 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by pageserv2.de (Postfix) with ESMTP id 3B61718F511 for ; Thu, 30 Aug 2007 22:44:44 +0200 (CEST) X-Virus-Scanned: amavisd-new at pageserv2.de Received: from pageserv2.de ([127.0.0.1]) by localhost (pageserv2.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FyPSBVmi6b3H for ; Thu, 30 Aug 2007 22:44:39 +0200 (CEST) Received: from [10.1.20.14] (unknown [10.1.20.14]) (Authenticated sender: dx_dominik_web@pageserv2.de) by pageserv2.de (Postfix) with ESMTP id 9B6FE18F556 for ; Thu, 30 Aug 2007 22:44:39 +0200 (CEST) Message-ID: <46D72C36.9010309@dbruhn.de> Date: Thu, 30 Aug 2007 22:44:38 +0200 From: Dominik Bruhn User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.4) Gecko/20070622 Thunderbird/2.0.0.4 Mnenhy/0.7.5.0 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Retrieving Columns by table-alias X-Enigmail-Version: 0.95.0 Content-Type: text/plain; charset=ISO-8859-15 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: 200708/106 X-Sequence-Number: 17419 Hy, I used MySQL for years and now wanted to try out something new (and perhaps better). Assume the following Tables: post: postid: serial postuserid: integer edituserid: integer user: userid: serial username: varchar Every "post" got two Users accociated to them, the onw who wrote it at first time (postuserid) and the last user who edited it (edituserid). So get a list of all post I use the following query: SELECT * FROM post LEFT JOIN user AS postuser ON (post.postuserid=postuser.userid) LEFT JOIN user AS edituser ON (post.edituserid=edituser.userid) This works fine until I want to retrieve the columns in JDBC: As "userid" is not a unique label (could be postuser.userid and edituser.userid) I need another solution. When using mysql I could write: ResultSet.getString("postuser.username") for example, so prefix the column with the table-alias. This syntax doesnt seem to be avaliable. Is there another solution? The only thing I could think of was to name all columns in the query like this: SELECT post.*, postuser.userid AS postuser_userid, postuser.username AS postuser_username, edituser.userid AS edituser_userid, edituser.username AS edituser_username FROM post LEFT JOIN user AS postuser ON (post.postuserid=postuser.userid) LEFT JOIN user AS edituser ON (post.edituserid=edituser.userid) BUT: This solution isnt what I want: Everytime I add another column to the user-table, I have to rewrite ALL Queries in Order to retrieve the data. I simply want it to access in the Result-Set. Can anybody give me a hint? Thanks in advance Dominik Bruhn