Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id C570D1C315B1 for ; Wed, 18 Apr 2012 12:09:18 -0300 (ADT) Received: from mail-gy0-f174.google.com ([209.85.160.174]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SKWVR-0005Wo-TR for pgsql-sql@postgresql.org; Wed, 18 Apr 2012 15:09:18 +0000 Received: by ghrr11 with SMTP id r11so3714885ghr.19 for ; Wed, 18 Apr 2012 08:09:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=cHB9P9jfOKLxXnVgj8IWJNzptB+MZyfBkzGOZz+Nmlo=; b=H5tMpy90nRqGYyyHA5NyAbnvsM5Vp76VwxSFsyD7ohDG8WEh6d9QAioRtSuIOeAoFi qLp+02Pjopdqvxq3vzqya3U4o7EOKeiV0lA6gY1LnjcsIDFCNrTypq2CGRDUw3wGxjMu jFlt+CKLwMCGCa058f64z8txISZ0yPinTSHhfy7BFoHdczT1vySGR3zdvOdXPRcXvkjz QP1Eka1MA9AZlkKMLHqY3ClPniA6YeIpZWP74pjtJdvhb7uziCvONutU19N5ULcWjOdI 5sSVZgtG8SiTEsFTAyPogowTsJ41DwhYd7pxlqcL5ROEZP+qWMPtpMU8EgsUTFOwz9Oq OJcg== Received: by 10.68.130.170 with SMTP id of10mr6679929pbb.156.1334761745119; Wed, 18 Apr 2012 08:09:05 -0700 (PDT) Received: from [172.16.1.88] ([208.187.158.94]) by mx.google.com with ESMTPS id nz8sm15958740pbb.68.2012.04.18.08.09.03 (version=SSLv3 cipher=OTHER); Wed, 18 Apr 2012 08:09:04 -0700 (PDT) Message-ID: <4F8ED973.8050305@gmail.com> Date: Wed, 18 Apr 2012 09:10:43 -0600 From: Rob Sargent User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Uniform UPDATE queries References: <4F8E936A.9050303@victorem.com> In-Reply-To: <4F8E936A.9050303@victorem.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201204/33 X-Sequence-Number: 36510 On 04/18/2012 04:11 AM, Dennis wrote: > 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 > Isn't this sort of shenanigans best left "one level up"? The client/app code construct the requisite update statement since it knows which actual columns need updating (i.e. have dirty values). This is actually quite straight forward when using O/R mapping tools such as hibernate or toplink (or whatever oracle calls it now). rjs