pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: dmp <danap@ttc-cmc.net>
To: pgsql-jdbc@postgresql.org
Subject: Re: Using ResultSetMetaData.getColumnTypeName
Date: Thu, 30 Sep 2010 10:23:28 -0600
Message-ID: <4CA4B980.1010108@ttc-cmc.net> (raw)
In-Reply-To: <201009301533.21174.david.goodenough@btconnect.com>
References: <201009301533.21174.david.goodenough@btconnect.com>

>
> I am trying to write some code to copy the definition of a database with all 
> its tables and keys, and I am trying to do it in Java using JDBC.  You may 
> think that I am mad and that there are better ways of doing this, but in this 
> case I am already within a Java app, and so using native facilities is more
> trouble than it is worth.
>
> The problem I have hit is that getColumnTypeName does not return say
> numeric or int for a number, but a size specific name like int4.  If you then
> use int4 as the type you can not use the precision (it is implicit I guess)
> in the column type.  So you can say "fred int(10)" or "fred int4" but not
> "fred int4(10)".  So I guess my question is whether there is a simple way
> to work out whether a given column type name is or is not allowed to be
> followed by a precision.
>
> I suppose I could use getColumnType and convert those into strings,
> but then one has to ask why getColumnTypeName exists.
>
> David
>
> BTW, I tried googling to find some code to do this, and I found some 
> MySql specific code but nothing for Postgresql.  If someone has already
> done this I would much rather use tested code than reinvent the wheel.
Hello,

I ran into similar problems with generating DDL in the MyJSQLView
project, and created code to I believe gather the information you
desire. I have not checked with the new PostgreSQL database release
or for that matter a couple of months since the updated release
of JDBC. You may find the source code at the Google Code, class
TableDefinitionGenerator under utilities/com/dandymadeproductions/myjsqlview

http://code.google.com/p/myjsqlview/source/browse/trunk/myjsqlview/src

If I remember correctly it was not straight forward and I have not
revisited to see if there is a better way.

danap.



view thread (2+ messages)

Message-ID: <4CA4B980.1010108@ttc-cmc.net>
Permalink:  ../4CA4B980.1010108@ttc-cmc.net/
Also on:    postgresql.org/message-id/4CA4B980.1010108@ttc-cmc.net

 · 

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: danap@ttc-cmc.net
  Subject: Re: Using ResultSetMetaData.getColumnTypeName
  In-Reply-To: <4CA4B980.1010108@ttc-cmc.net>
  References: <201009301533.21174.david.goodenough@btconnect.com> <4CA4B980.1010108@ttc-cmc.net>

* 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