title: Is it correct that "ResultSet.getMetaData.getTableName(col)" of postgresql's jdbc driver is always returning an empty string?
body: <p>When I use postgresql, I found following code:</p>
  
  <pre><code>Statement stmt = conn.createStatement();
  ResultSet rs = stmt.executeQuery("select * from t");
  
  String tableName = rs.getMetaData().getTableName(1);
  System.out.println(tableName);
  </code></pre>
  
  <p>It prints an empty string.</p>
  
  <p>So I checked the source code, and found the method <code>org.postgresql.jdbc2.AbstractJdbc2ResultSetMetaData#getTableName</code> always returns an empty string.</p>
  
  <p>The source code is:</p>
  
  <pre><code>public abstract class AbstractJdbc2ResultSetMetaData implements PGResultSetMetaData {
  
      /*
       * @param column the first column is 1, the second is 2...
       * @return column name, or "" if not applicable
       * @exception SQLException if a database access error occurs
       */
      public String getTableName(int column) throws SQLException
      {
          return "";
      }
  }
  </code></pre>
  
  <p>You can see it just return a <code>""</code>.</p>
  
  <p>I found a discussion about this, please see: <a href="http://archives.postgresql.org/pgsql-jdbc/2009-12/msg00100.php" rel="nofollow noreferrer">http://archives.postgresql.org/pgsql-jdbc/2009-12/msg00100.php</a></p>
  
  <p>They think 
  "rs.getMetaData.getTableName(col)" should return the alias name in 
  query not the underlying table name. But which is hard to implement, so it's better to leave it empty.</p>
  
  <p>Also they gave a method to get the table name, use: </p>
  
  <pre><code>PGResultSetMetaData.getBaseTableName() 
  </code></pre>
  
  <p>Sample:</p>
  
  <pre><code>ResultSet rs = stmt.executeQuery("select * from x");
  // convert it to PGResultSetMetaData 
  PGResultSetMetaData meta = (PGResultSetMetaData)rs.getMetaData(); 
  String tableName = meta.getBaseTableName(1);
  </code></pre>
  
  <p>Now it can print the correct table name.</p>
  
  <p>I don't know the implementation of postgresql is correct, but returning the underlying table name is much more useful than an empty string, and, most of other databases provides underlying table name instead of an empty string.</p>
  
  <p>I have a problem using play2's anorm framework with postgesql: <a href="https://stackoverflow.com/questions/9247064/play2s-anorm-cant-work-on-postgresql">Play2&#39;s anorm can&#39;t work on postgresql</a>, but that works well on other databases.</p>
  
  <p>What do you think the correct implementation of postgresql's jdbc driver? Return an empty string, underlying table name, or something else?</p>