X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 69EEB9DC894 for ; Mon, 20 Feb 2006 10:33:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 05000-08 for ; Mon, 20 Feb 2006 10:33:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp.uk.colt.net (smtp.uk.colt.net [195.110.64.125]) by postgresql.org (Postfix) with ESMTP id E26B29DC851 for ; Mon, 20 Feb 2006 10:33:31 -0400 (AST) Received: from [10.0.1.82] (unknown [212.161.21.117]) by smtp.uk.colt.net (Postfix) with ESMTP id BF6C6417BA for ; Mon, 20 Feb 2006 14:35:43 +0000 (GMT) From: David Goodenough To: pgsql-jdbc@postgresql.org Subject: Re: setString and timestamps Date: Mon, 20 Feb 2006 14:31:55 +0000 User-Agent: KMail/1.9.1 References: <200602171607.18071.david.goodenough@btconnect.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200602201431.55800.david.goodenough@btconnect.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.559 required=5 tests=[AWL=-0.360, DNS_FROM_RFC_ABUSE=0.479, DNS_FROM_RFC_POST=1.44] X-Spam-Score: 1.559 X-Spam-Level: * X-Archive-Number: 200602/151 X-Sequence-Number: 14748 On Friday 17 February 2006 18:33, Kris Jurka wrote: > On Fri, 17 Feb 2006, David Goodenough wrote: > > I understand from looking at the archive that there some changes around > > 8.0 in this area, but I am confused as to how to proceed. > > > > I have some code which takes a table and inserts values into it where the > > values have come from XML and are thus all strings. Some of these XML > > fields are timestamps, but this generic code does not have table specific > > knowledge. > > > > From what I have read I think I have to use something like the metadata > > for this table to find the type of this column, and if it is a timestamp > > then I need to take the string and convert it into a timestamp before I > > set it into the parameterized insert. Is this right, and are there any > > other datatypes which are not implicitly converted from String to > > whatever is necessary? > > In the 8.0 and 8.1 driver all types have strong typing information. You > can see this with integers as well. The driver will do the equivalent of: > > jurka=# create table inttest(a int); > CREATE TABLE > jurka=# insert into inttest values('1'::varchar); > ERROR: column "a" is of type integer but expression is of type character > varying > HINT: You will need to rewrite or cast the expression. > > If you really have only string data and no typing information your best > bet is probably to use an 8.2dev driver and set the stringtype=unspecified > URL parameter to restore the old behavior of automatic type > interpretation. > > http://jdbc.postgresql.org/documentation/head/connect.html#connection-param >eters > > Kris Jurka > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend What is the best way of finding the column types in generic code. That is to say if I have a method with no knowledge of a specific table and I am about to do an insert and I wish to get the parameters in the correct format what APIs exist that allow me to find out the type of a named column. I have looked through the JDBC docs without success so far, but it may be that I am looking for the wrong thing. If I need to use a Postgresql only API that is fine. Thanks David