Received: from sysadmin.chi.wdr.com (sysadmin.chi.ubswarburg.com [146.180.1.66]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f1OFxOx78707 for ; Sat, 24 Feb 2001 10:59:24 -0500 (EST) (envelope-from devin@sysadmin.chi.wdr.com) Received: from devin by sysadmin.chi.wdr.com with local (Exim 3.12 #2) id 14Wh6I-0003SG-00; Sat, 24 Feb 2001 09:59:14 -0600 Date: Sat, 24 Feb 2001 09:59:12 -0600 (CST) From: Tod McQuillin X-X-Sender: To: postgresql cc: PgSQL-SQL Subject: Re: syntax prob In-Reply-To: <200102240217.f1O2Hhx35303@mail.postgresql.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200102/385 X-Sequence-Number: 1590 On Fri, 23 Feb 2001, postgresql wrote: > when doing updates of multiple fields there commas between > the elements? Yes. update t set a=b, c=d where ... > if I could get to the server I would just try it. what happens if you have > only 1 field to update and you add a comma, like this > > update table set cname = 'Bill', where acode = 'AVAN'; You get: ERROR: parser: parse error at or near "where" > I am trying to concatenate an update string and I would love to not > have to worry about the comma. Here's what I do. I keep a list of the things I am updating, like this, in perl: push(@updates, "set a=b"); push(@updates, "set c=d"); $sql = "update t " . join(", ", @updates) . " where ..."; or like this in php: $updates[] = "set a=b"; $updates[] = "set c=d"; $sql = "update t " . implode(", ", $updates) . " where ..."; The join() and implode() functions make sure no comma is used if the updates array has fewer than two elements. Otherwise they stick commas between each one, just like sql wants. -- Tod McQuillin