pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Getting views' metadata
2+ messages / 2 participants
[nested] [flat]

* Getting views' metadata
@ 2009-06-09 11:53  Gaël BOUGANNE <gael.bouganne@univ-nantes.fr>
  0 siblings, 1 reply; 2+ messages in thread

From: Gaël BOUGANNE @ 2009-06-09 11:53 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,

i'm trying to retrieve complete metadata of my pgsql 8.3 database using 
JDBC.
But i got a problem getting the columns informations of views.
I succesfully get the view names using 'getTables(...)' method, but when 
calling 'getColumns(...)' for a given view, the returned ResultSet is empty.

So i wonder wether it is possible to get such information or not. If it 
is possible how shall i do?

Regards,

Gaël BOUGANNE



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Getting views' metadata
@ 2009-06-10 22:53  Kris Jurka <books@ejurka.com>
  parent: Gaël BOUGANNE <gael.bouganne@univ-nantes.fr>
  0 siblings, 0 replies; 2+ messages in thread

From: Kris Jurka @ 2009-06-10 22:53 UTC (permalink / raw)
  To: Gaël BOUGANNE <gael.bouganne@univ-nantes.fr>; +Cc: pgsql-jdbc



On Tue, 9 Jun 2009, Ga?l BOUGANNE wrote:

> i'm trying to retrieve complete metadata of my pgsql 8.3 database using 
> JDBC. But i got a problem getting the columns informations of views. I 
> succesfully get the view names using 'getTables(...)' method, but when 
> calling 'getColumns(...)' for a given view, the returned ResultSet is 
> empty.

It certainly works for me (as attached).  If you can produce a similar 
counterexample which doesn't work, I'll certainly try and figure out 
what's wrong.

Kris Jurka

Attachments:

ViewMD.java (text/plain, 1.1K) download import java.sql.*; public class ViewMD { public static void main(String args[]) throws Exception { Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5844/jurka","jurka",""); Statement stmt = conn.createStatement(); stmt.execute("CREATE TEMP TABLE mytemptable (a int, b text)"); stmt.execute("CREATE TEMP VIEW mytempview AS SELECT a, b, 3 as c FROM mytemptable"); stmt.close(); DatabaseMetaData dbmd = conn.getMetaData(); ResultSet rs = dbmd.getColumns("%", "%", "mytempview", "%"); printResultSet(rs); conn.close(); } public static void printResultSet(ResultSet rs) throws SQLException { ResultSetMetaData rsmd = rs.getMetaData(); for (int i = 1; i <= rsmd.getColumnCount(); i++) { if (i != 1) { System.out.print(", "); } System.out.print(rsmd.getColumnName(i)); } System.out.println(); while (rs.next()) { for (int i = 1; i <= rsmd.getColumnCount(); i++) { if (i != 1) { System.out.print(", "); } System.out.print(rs.getString(i)); } System.out.println(); } } }
^ permalink raw reply [nested|flat] 2+ messages in thread


end of thread, other threads:[~2009-06-10 22:53 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-06-09 11:53 Getting views' metadata Gaël BOUGANNE <gael.bouganne@univ-nantes.fr>
2009-06-10 22:53 ` Kris Jurka <books@ejurka.com>

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