Kris Jurka wrote:
> This shows the results are different, but it doesn't indicate why. Is it
> simply because the other dbs can't implement getColumnName as we have?
> I certainly wouldn't expect this to be a common feature.
>
> Further it doesn't show that users can't write portable code using the
> ResultSetMetaData calls. It shows all drivers returning the same value
> for getColumnLabel that you would expect. Earlier you had speculated that
> other drivers would return something different for this, but you haven't
> shown that. Yes it may break existing code, but it doesn't show that they
> weren't simply using the wrong call.
I'm leaning towards Mike's argument here. It seems reasonable that the
column name returned is the same as what you'd use to look up a column
by name via ResultSet, and the only sensible thing to do in ResultSet
lookups is to use the column aliases.
The argument for exposing the real column name as a way to allow
portable updating of the underlying table seems weak given that other
drivers don't support the same behaviour. The more portable behaviour
seems to be to always use getColumnName() and forbid the use of AS in
queries that you want to be updatable.
getColumnLabel() isn't the right place for the underlying column name,
though. JDBC doesn't actually seem to have a mapping for this concept at
all. I'd suggest adding a PG-specific interface if we want to expose
this. How about:
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.
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".
-O