Lists: | pgsql-jdbc |
---|
From: | Hugo Garza <hiro2k(at)gmail(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | My query table aliases don't exist in my application |
Date: | 2011-02-01 22:23:06 |
Message-ID: | AANLkTimBHzeWSsKxC7ZhziKiehCmCgyiUdD3Q76yNrSy@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-jdbc |
Hello everyone,
I'm going a complex join on 5 tables and some of them have a column that
repeats in two tables called "name". So I created an alias for each table,
one of them called co, and in my application I do a result.getString("
co.name"). But the application fails with: "The column name co.name was not
found in this ResultSet."
When I test this same code against a MySQL database it returns the right
column. I tried doing just a result.getString("name") but as I expected it
just returned the first column called "name" instead of the one I want.
Is this a bug in the JDBC driver, or am I doing it wrong?
From: | "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov> |
---|---|
To: | "Hugo Garza" <hiro2k(at)gmail(dot)com>,<pgsql-jdbc(at)postgresql(dot)org> |
Subject: | Re: My query table aliases don't exist in my application |
Date: | 2011-02-01 22:48:00 |
Message-ID: | 4D483940020000250003A145@gw.wicourts.gov |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-jdbc |
Hugo Garza <hiro2k(at)gmail(dot)com> wrote:
> I'm going a complex join on 5 tables and some of them have a
> column that repeats in two tables called "name". So I created an
> alias for each table, one of them called co, and in my application
> I do a result.getString("co.name"). But the application fails
> with: "The column name co.name was not found in this ResultSet."
Try giving the result column an alias:
select co.name as co_name
Then access it by the name you have given it.
Personally, I've never seen that other usage, and would never have
expected it to work.
-Kevin
From: | Maciek Sakrejda <msakrejda(at)truviso(dot)com> |
---|---|
To: | Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov> |
Cc: | Hugo Garza <hiro2k(at)gmail(dot)com>, pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: My query table aliases don't exist in my application |
Date: | 2011-02-01 22:52:27 |
Message-ID: | AANLkTinVeH7vHo10GUSG3c412J5H0odEx3gjk6meL7Mh@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-jdbc |
Right. Even if you explicitly include the table alias, PostgreSQL
strips it out before sending column metadata, so according to the
server, the column name of
SELECT x.a FROM foo x;
is just "a", not "x.a". The driver is just playing along. If you
really like the alias names, you can use the somewhat perverse
SELECT x.a as "x.a" FROM foo x;
---
Maciek Sakrejda | System Architect | Truviso
1065 E. Hillsdale Blvd., Suite 215
Foster City, CA 94404
www.truviso.com
From: | Hugo Garza <hiro2k(at)gmail(dot)com> |
---|---|
To: | Maciek Sakrejda <msakrejda(at)truviso(dot)com> |
Cc: | Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>, pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: My query table aliases don't exist in my application |
Date: | 2011-02-02 17:03:08 |
Message-ID: | AANLkTiknR7yUeK+VUPGFVuQonMoMkfyZ90oyOtU8sSXE@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-jdbc |
Thank you guys, I will have to update my program code. But it makes a lot
more sense to have the columns with more signifcant names.
On Tue, Feb 1, 2011 at 4:52 PM, Maciek Sakrejda <msakrejda(at)truviso(dot)com>wrote:
> Right. Even if you explicitly include the table alias, PostgreSQL
> strips it out before sending column metadata, so according to the
> server, the column name of
>
> SELECT x.a FROM foo x;
>
> is just "a", not "x.a". The driver is just playing along. If you
> really like the alias names, you can use the somewhat perverse
>
> SELECT x.a as "x.a" FROM foo x;
>
> ---
> Maciek Sakrejda | System Architect | Truviso
>
> 1065 E. Hillsdale Blvd., Suite 215
> Foster City, CA 94404
> www.truviso.com
>