Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id DB6211337B50 for ; Thu, 30 Sep 2010 11:55:50 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 77354-01-5 for ; Thu, 30 Sep 2010 14:55:36 +0000 (UTC) X-Greylist: delayed 00:21:48.372098 by SQLgrey-1.7.6 Received: from mail.ukfsn.org (mail.ukfsn.org [77.75.108.10]) by mail.postgresql.org (Postfix) with ESMTP id D8F091337B5D for ; Thu, 30 Sep 2010 11:55:12 -0300 (ADT) Received: from localhost (smtp-filter.ukfsn.org [192.168.54.205]) by mail.ukfsn.org (Postfix) with ESMTP id A4FD6DEC4B for ; Thu, 30 Sep 2010 15:33:23 +0100 (BST) Received: from mail.ukfsn.org ([192.168.54.25]) by localhost (smtp-filter.ukfsn.org [192.168.54.205]) (amavisd-new, port 10024) with ESMTP id z5fX1-MEnyFF for ; Thu, 30 Sep 2010 15:33:23 +0100 (BST) Received: from stargate.localnet (unknown [84.45.236.142]) by mail.ukfsn.org (Postfix) with ESMTP id 594BCDEC47 for ; Thu, 30 Sep 2010 15:33:23 +0100 (BST) From: David Goodenough To: pgsql-jdbc@postgresql.org Subject: Using ResultSetMetaData.getColumnTypeName Date: Thu, 30 Sep 2010 15:33:21 +0100 User-Agent: KMail/1.13.5 (Linux/2.6.32-2-686; KDE/4.4.5; i686; ; ) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201009301533.21174.david.goodenough@btconnect.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201009/88 X-Sequence-Number: 20958 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.