X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B6B82D1B4CA for ; Thu, 29 Jul 2004 19:47:31 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 05977-04 for ; Thu, 29 Jul 2004 22:47:23 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 7117FD1B462 for ; Thu, 29 Jul 2004 19:47:20 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i6TMlJqb030670 for ; Thu, 29 Jul 2004 22:47:19 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i6TMa7OJ029340 for pgsql-jdbc@postgresql.org; Thu, 29 Jul 2004 22:36:07 GMT From: "Mike Martin" X-Newsgroups: comp.databases.postgresql.interfaces.jdbc Subject: Re: Wrong column names in ResultSetMetaData Date: Thu, 29 Jul 2004 17:36:07 -0500 Organization: Vieo, Inc. Lines: 72 Message-ID: References: X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 To: pgsql-jdbc@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.8 tagged_above=0.0 required=5.0 tests=PRIORITY_NO_NAME X-Spam-Level: X-Archive-Number: 200407/330 X-Sequence-Number: 10714 Kris Jurka wrote: > > 2. Every other JDBC driver I'm familiar with behaves that way > > (with the exception, I hear, of MimerSQL, which confuses > > getColumnLabel() with SQL alias the way our new code does). > > What do they return for getColumnLabel()? Previously we returned the same > value for both methods simply because we couldn't implement getColumnName > as we do now. If they all return the alias in getColumnLabel that would > be telling. Most return the same thing as getColumnName(); not surprising since that's a good default display title. I've heard that some drivers return a string containing extra metadata fluff about the column type. Consider: SELECT c1 + c2 FROM t1 The name/label distinction allows the DBMS/driver, if it wants, to give the column a label for display purposes of, say, "Expr c1+c2" or "Result, type=decimal(9,2)". But the column has no SQL name. Nor could it have a name like "Expr c1+c2" since that's not a valid SQL identifier. > > I'm not clear why a JDBC client would want or need to know the > > "underlying" column name, if there even is one. I can see why > > the driver might need to know that internally for purposes of > > updateability but that's something different. > > To allow client software to do the updates or allow the user to navigate > from a query result column to the base table or to/through foreign keys on > it. There could be a number of uses. What about: SELECT col1 AS price FROM t1 UNION SELECT col2 AS price FROM t2 What is the "true" column name? SQL says that query produces a table with one column named "PRICE". Client code simply can't reverse-engineer query result columns to find their origins. If a user is trying to do so for updating, that's what updatable result sets are for, and that's why only a small subset of queries are updatable. From http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec2/jdbc2.1.frame5.html: Due to differences in database implementations, the JDBC API does not specify an exact set of SQL queries which must yield an updatable result set for JDBC drivers that support updatability. Developers can, however, generally expect queries which meet the following criteria to produce an updatable result set: 1. The query references only a single table in the database. 2. The query does not contain any join operations. 3. The query selects the primary key of the table it references. In addition, an SQL query should also satisfy the conditions listed below if inserts are to be performed. 4. The query selects all of the non-nullable columns in the underlying table. 5. The query selects all columns that don't have a default value. Mike