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 F10AA9DC83C for ; Tue, 10 Jan 2006 00:21:18 -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 97562-04 for ; Tue, 10 Jan 2006 00:21:17 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by postgresql.org (Postfix) with SMTP id A03D49DC83E for ; Tue, 10 Jan 2006 00:21:16 -0400 (AST) Received: (qmail 32645 invoked from network); 10 Jan 2006 04:21:15 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.2?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 10 Jan 2006 04:21:15 -0000 In-Reply-To: <4bd3e1480601092002m7f637397nef9654c5014f4785@mail.gmail.com> References: <4bd3e1480601091924q54cfee5cs1c6744638e650fff@mail.gmail.com> <43C32A5D.8020807@computer.org> <4bd3e1480601092002m7f637397nef9654c5014f4785@mail.gmail.com> Mime-Version: 1.0 (Apple Message framework v746.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <377962F9-1235-4413-94AA-3E2BCBA12B59@fastcrypt.com> Cc: David Wall , pgsql-jdbc@postgresql.org Content-Transfer-Encoding: 7bit From: Dave Cramer Subject: Re: Prepared statements and default values Date: Mon, 9 Jan 2006 23:21:10 -0500 To: Assad Jarrahian X-Mailer: Apple Mail (2.746.2) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.127 required=5 tests=[AWL=0.127] X-Spam-Score: 0.127 X-Spam-Level: X-Archive-Number: 200601/37 X-Sequence-Number: 14488 Actually, I don't think not specifying the column will work. This works for insert, but not update. I don't think there is a way using JDBC, as you can't even use the keyword DEFAULT. The driver won't let you bind a string to a non- string parameter. Dave On 9-Jan-06, at 11:02 PM, Assad Jarrahian wrote: > thanks for your response David! > > Is that the only way, cause that surely does not seem easy when you > have say 20 columns, of which 15 have default values. > > given all the combinations (sometimes this set of column values is > needed to be default, otherwise another set .... and so on. > > Am I stuck with writing out all possible statements ...or is there > another way? > > thanks. > -assad > > > On 1/9/06, David Wall wrote: >> You'll probably need to use two statements, so that when you want >> to use >> the default, you don't specify anything, and when you want a special >> value, you use the command you gave. >> >> If you want the default, use: >> >> UPDATE usersettings SET serverurl = ? where username = ? >> >> If you want to specify, then use: >> >> UPDATE usersettings SET gpsfrequency = ? , serverurl = ? where >> username = ? >> >> David >> >> >> Assad Jarrahian wrote: >> >>> I have a preparedStatement with the following query >>> "UPDATE usersettings SET gpsfrequency = ? , serverurl = ? where >>> username = ? ;"; >>> >>> In the db, the table userSettings has a default value specified for >>> gps_frequency . >>> >>> So when I write code >>> if (client.getSettings().getField >>> (Settings.GPS_FREQUENCY).compareTo(""))==0) >>> //pick up the default value from the db. >>> else >>> setUserSettings.setInt(++i, >>> Integer.parseInt(client.getSettings().getField >>> (Settings.GPS_FREQUENCY))); >>> >>> >>> .. I basically want to send something that lets the >>> db know to use the DEFAULT value. (its of type int0) >>> >>> So what does go here? >>> >>> any help would be much appreciated. >>> >>> -a >>> >>> ---------------------------(end of >>> broadcast)--------------------------- >>> TIP 2: Don't 'kill -9' the postmaster >>> >>> >>> >> >> ---------------------------(end of >> broadcast)--------------------------- >> TIP 6: explain analyze is your friend >> > > ---------------------------(end of > broadcast)--------------------------- > TIP 4: Have you searched our list archives? > > http://archives.postgresql.org >