Re: Update multiple rows in a table with different values

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: shankha <shankhabanerjee(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Update multiple rows in a table with different values
Date: 2016-07-01 14:59:44
Message-ID: 19750.1467385184@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

shankha <shankhabanerjee(at)gmail(dot)com> writes:
> PREPARE updatearrayplan(BigInt[], BigInt[]) AS
> for i in size($1)
> DO
> update s.t1
> SET c3 = $2[$i]
> WHERE c2 = $1[$i]
> END FOR

> In this prepared statement I am just trying to explain the algorithm.
> I do not know the exact syntax.

You would need to write a plpgsql function in order to have a loop like
that; there's no loops in bare SQL.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sfiligoi, Igor 2016-07-01 17:17:55 PSQL does not remove obvious useless joins
Previous Message shankha 2016-07-01 14:51:01 Re: Update multiple rows in a table with different values