Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 929D71F66B30 for ; Wed, 18 Apr 2012 05:12:10 -0300 (ADT) Received: from fep17.mx.upcmail.net ([62.179.121.37]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SKPzj-0006Dl-Uw for pgsql-sql@postgresql.org; Wed, 18 Apr 2012 08:12:09 +0000 Received: from edge01.upcmail.net ([192.168.13.236]) by viefep17-int.chello.at (InterMail vM.8.01.05.05 201-2260-151-110-20120111) with ESMTP id <20120418081154.NQTM23101.viefep17-int.chello.at@edge01.upcmail.net> for ; Wed, 18 Apr 2012 10:11:54 +0200 Received: from titikaka.workgroup ([46.129.89.21]) by edge01.upcmail.net with edge id zLBt1i0390TeGUW01LBtKF; Wed, 18 Apr 2012 10:11:54 +0200 X-SourceIP: 46.129.89.21 X-Authenticated-Sender: dennis.verbeek Message-ID: <4F8E936A.9050303@victorem.com> Date: Wed, 18 Apr 2012 12:11:54 +0200 From: Dennis User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120312 Thunderbird/11.0 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Uniform UPDATE queries Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.1 (-) X-Archive-Number: 201204/32 X-Sequence-Number: 36509 When a query is written to update a table, the usual process is to list all the columns that need updating. This could imply the creation of many possible queries for many columns. In an effort to keep the UPDATE queries more uniform, less number of unique queries, a keyword similar to DEFAULT, let's say CURRENT, is required to indicate that the current value must not change. Examples: update mytable set ( d ) = ("newvalue") This is the usual way to change values in column "d" and requires writing a new query for updating every column. update mytable set ( a, b, c, d ) = ( a, b, c, "newvalue" ) This sort of works to change only column "d", but requires explicit naming of the columns on the value side. My suggestion is to introduce the CURRENT keyword: update mytable set ( a, b, c, d ) = ( CURRENT, CURRENT, CURRENT, "newvalue" ) This could then lead to the uniform prepared JDBC statement: update mytable set ( a, b, c, d ) = ( ?, ?, ?, ? ) where id = ( ? ); And then the JDBC driver could be improved to accept stmt.setString( 4, "newvalue" ) and automagically substitute the first three parameters with CURRENT when the query is executed. Note the added WHERE clause? The parameter for id is always on the same index. This makes the bookkeeping a lot easier and should reduce the need for generating UPDATE queries or even client JDBC code. -- Dennis Verbeek