Re: Wrong column names in ResultSetMetaData

Поиск
Список
Период
Сортировка
От Mike Martin
Тема Re: Wrong column names in ResultSetMetaData
Дата
Msg-id cemmc3$2ke7$1@news.hub.org
обсуждение исходный текст
Ответ на Re: Wrong column names in ResultSetMetaData  ("Mike Martin" <mmartin@vieo.com>)
Список pgsql-jdbc
Oliver wrote:
>    RSMD.getColumnName() returns the column alias
>    RSMD.getColumnLabel() returns the column alias, or maybe something
> like the column's comment (can you COMMENT ON columns?) later.
>    PGResultSetMetadata.getSourceColumnName() returns the underlying
> table column name. The driver's updateable resultset code can use this
> when constructing update SQL.

I like that, not just because I think it jives with the spec
but because a new method can explicitly document that the
source column name is not available if the result column has
multiple sources.

> On a related note, if I execute this query:
>
>    SELECT * FROM footable f
>
> should RSMD.getTableName() return "footable" or "f"? By analogy to
> RSMD.getColumnName() it should return "f", but it seems more useful to
> return "footable".

According to SQL "f" is the right answer.  One way convince yourself
is to observe the difference between:

     SELECT f.col FROM footable f
     SELECT footable.col FROM footable f

The former works as you might expect.  The latter fails on some
DBMS's and I'm pretty sure it's invalid SQL.  Interestingly, on
PG the latter is evaluated as though it were:

     SELECT f2.col FROM footable f1 CROSS JOIN footable f2

which for a footable of N rows returns N*N rows!

Mike



В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "Mike Martin"
Дата:
Сообщение: Re: Wrong column names in ResultSetMetaData
Следующее
От: Kris Jurka
Дата:
Сообщение: Re: Wrong column names in ResultSetMetaData