Re: UPDATE syntax problem

From: Medi Montaseri <medi(dot)montaseri(at)intransa(dot)com>
To: MT <mt(at)open2web(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>, Carlos Moreno <moreno(at)mochima(dot)com>
Subject: Re: UPDATE syntax problem
Date: 2002-12-09 19:33:53
Message-ID: 3DF4F021.8040501@intransa.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

MT wrote:

> Hi,
>
> }
> else if (param["new_unitcnt"] != param["old_unitcnt"])
> {
> sql += "unitcnt = '" + param["new_unitcnt"] + "',";
> }
> else if (param["new_wprice"] != param["old_wprice"])
> {
> sql += "wprice = " + param["new_wprice"];
> }
>
> sql += "WHERE prodid = '" + param["prodid"] + "'";
>
> int res = conn.Exec (sql.c_str()); //sql exec
>
> Now the problem occurs when a user only wants to update certain columns,
> which creates a syntax problem due to the comma (","). In other words
> you cannot end a multiple column UPDATE statement with a comma
> followed by:

Before you process the WHERE clause....you need to backtrack and delete any
dangling ','. I'm not sure how you'd do it in pure C++ but in perl you'd say

$SQL =~ s/,$//

ie remove the last comma....

You'll also run into this problem when constructing WHERE clause items
where you
have have a 'AND' or similar operators at the end....

> er the program will run.
>
> Thanks,
>
> Mark Tessier
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2002-12-09 19:49:44 Re: 7.3 no longer using indexes for LIKE queries
Previous Message Tom Lane 2002-12-09 18:22:49 Re: table functions