Re: UPDATE with multiple WHERE conditions

From: Ron Johnson <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: UPDATE with multiple WHERE conditions
Date: 2024-06-12 21:48:26
Message-ID: CANzqJaB48SjPZrOqEn-wawob+GfKQrwLouyNP_zoPW_5QsvFFw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jun 12, 2024 at 5:28 PM Rich Shepard <rshepard(at)appl-ecosys(dot)com>
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?)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rob Sargent 2024-06-12 22:05:26 Re: UPDATE with multiple WHERE conditions
Previous Message Ron Johnson 2024-06-12 21:37:22 Re: PG16.1 security breach?