pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
syntax prob 2+ messages / 2 participants [nested] [flat]
* syntax prob @ 2001-02-24 02:24 postgresql <pgsql@symcom.com> 2001-02-24 15:59 ` Re: syntax prob Tod McQuillin <devin@spamcop.net> 0 siblings, 1 reply; 2+ messages in thread From: postgresql @ 2001-02-24 02:24 UTC (permalink / raw) To: pgsql-sql I am away from my server for the weekend and I need a little help. when doing updates of multiple fields there commas between the elements? I mean update table set cname = 'Bill', caddress = '2nd floor' where acode = 'AVAN'; I refer to the space between 'Bill' and caddress. 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'; I am trying to concatenate an update string and I would love to not have to worry about the comma. I guess I could figure out how many things have changed then add commas... but I could also wish for it to be easier. Ted ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: syntax prob 2001-02-24 02:24 syntax prob postgresql <pgsql@symcom.com> @ 2001-02-24 15:59 ` Tod McQuillin <devin@spamcop.net> 0 siblings, 0 replies; 2+ messages in thread From: Tod McQuillin @ 2001-02-24 15:59 UTC (permalink / raw) To: postgresql <pgsql@symcom.com>; +Cc: pgsql-sql 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 ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2001-02-24 15:59 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2001-02-24 02:24 syntax prob postgresql <pgsql@symcom.com> 2001-02-24 15:59 ` Tod McQuillin <devin@spamcop.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox