Subject: Re: UPDATE with multiple WHERE conditions

From: Ron Johnson <[email-masked]>
Date: Wed, 12 Jun 2024 17:48:26 -0400

On Wed, Jun 12, 2024 at 5:28 PM Rich Shepard <[email-masked]>
wrote:

> I have a table with 3492 rows. I want to update a boolean column from
> 'false' to 'true' for 295 rows based on the value of another column.
>
> Is there a way to access a file with those condition values? If not, should
> I create a temporary table with one column containing those values, or do I
> write a psql script with 295 lines, one for each row to be updated?
>

A plain UPDATE might work.

UPDATE to_be_updated a
SET bool_col = true
FROM other_table b
WHERE a.pk = b.pk
  AND b.field3 = mumble;

(You can join them, right?)

---

From: Rob Sargent <[email-masked]>
Date: Wed, 12 Jun 2024 16:05:26 -0600

On 6/12/24 15:48, Ron Johnson wrote:
> On Wed, Jun 12, 2024 at 5:28 PM Rich Shepard 
> <[email-masked]> wrote:
>
> WHERE a.pk <http://a.pk> = b.pk <http://b.pk>
>   AND b.field3 = mumble;
>
Add "begin;" to that and try it.  If you don't get exactly UPDATE 295 
reported, then "rollback;";

---

From: Rich Shepard <[email-masked]>
Date: Wed, 12 Jun 2024 15:46:37 -0700 (PDT)

> (You can join them, right?)

Thanks, Ron.

Rich

---

From: Rich Shepard <[email-masked]>
Date: Wed, 12 Jun 2024 15:47:24 -0700 (PDT)

> reported, then "rollback;";

Got it, thanks.

Rich