pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Florence Cousin <cousinflo@free.fr>
To: pgsql-jdbc@postgresql.org
Subject: Patch for the documentation (PGResultSetMetaData)
Date: Tue, 20 Jul 2010 22:40:21 +0200
Message-ID: <201007202240.22057.cousinflo@free.fr> (raw)

Hi,

I have written a short text to explain the use of PGResultSetMetaData, with an 
example.
Your comments are welcome.

Regards,

Florence.

Attachments:

pgjdbc.xml.patch (text/x-patch, 3.3K) download *** pgjdbc.xml.old 2009-06-20 17:19:40.000000000 +0200 --- pgjdbc.xml 2010-07-20 22:15:26.543010752 +0200 *************** *** 3187,3192 **** --- 3187,3255 ---- </sect1> </chapter> + <chapter id="resultset-metadata"> + <title>PGResultSetMetaData interface</title> + <para> + If a column is aliased in the query, the standard <classname>ResultSetMetaData</classname> interface can not determine the schema and table name for this column. + So for consistency reasons, getColumnName and getSchemaName always returns a zero-length string (""). + </para> + <para> + To determine the names of the underlying columns, table and schema of the <classname>ResultSet</classname>, you have to use the <classname>PGResultSetMetaData</classname> interface. + This interface gives the names of the columns, table and schema of the underlying base column, table or schema name if it can determine it. Note that is not possible when the column is an operation (see example below). + </para> + <example id="resultset-metadata-example"> + <title>Using ResultSetMetaData and PGResultSetMetaData</title> + <programlisting> + Statement stmt = null; + ResultSet resultSet = null; + + // Query + String sql = "SELECT city as town, temp_lo + 273 , temp_hi FROM weather"; + try { + stmt = connexion.createStatement(); + resultSet = stmt.executeQuery(sql); + + // Metadata + ResultSetMetaData rsm; + PGResultSetMetaData pgRsm; + + rsm = resultSet.getMetaData(); + pgRsm = (PGResultSetMetaData)rsm; + + System.out.println("1rst column : "); + System.out.println("column name : " + rsm.getColumnName(1) + "; base column : " + pgRsm.getBaseColumnName(1)); + System.out.println("table name : " + rsm.getTableName(1) + "; base table : " + pgRsm.getBaseTableName(1)); + System.out.println("schema name : " + rsm.getSchemaName(1) + "; base schema : " + pgRsm.getBaseSchemaName(1)); + System.out.println("2nd column : "); + System.out.println("column name : " + rsm.getColumnName(2) + "; base column : " + pgRsm.getBaseColumnName(2)); + System.out.println("table name : " + rsm.getTableName(2) + "; base table : " + pgRsm.getBaseTableName(2)); + System.out.println("schema name : " + rsm.getSchemaName(2) + "; base schema: " + pgRsm.getBaseSchemaName(2)); + System.out.println("3rd column : "); + System.out.println("column name : " + rsm.getColumnName(3) + "; base column : " + pgRsm.getBaseColumnName(3)); + System.out.println("table name : " + rsm.getTableName(3) + "; base table : " + pgRsm.getBaseTableName(3)); + System.out.println("schema name : " + rsm.getSchemaName(3) + "; base schema: " + pgRsm.getBaseSchemaName(3)); + + </programlisting> + <para> + Which will produce the following output : + </para> + <programlisting> + 1rst column : + column name : town; base column : city + table name : ; base table : weather + schema name : ; base schema : public + 2nd column : + column name : ?column?; base column : + table name : ; base table : + schema name : ; base schema: + 3rd column : + column name : temp_hi; base column : temp_hi + table name : ; base table : weather + schema name : ; base schema: public + + </programlisting> + </example> + </chapter> <chapter id="reading"> <title>Further Reading</title>

Message-ID: <201007202240.22057.cousinflo@free.fr>
Permalink:  ../201007202240.22057.cousinflo@free.fr/
Also on:    postgresql.org/message-id/201007202240.22057.cousinflo@free.fr

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: cousinflo@free.fr
  Subject: Re: Patch for the documentation (PGResultSetMetaData)
  In-Reply-To: <201007202240.22057.cousinflo@free.fr>
  References: <201007202240.22057.cousinflo@free.fr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox