public inbox for [email protected]  
help / color / mirror / Atom feed
From: Rob Sargent <[email protected]>
To: [email protected]
Subject: Re: UPDATE with multiple WHERE conditions
Date: Wed, 12 Jun 2024 16:05:26 -0600
Message-ID: <[email protected]> (raw)
In-Reply-To: <CANzqJaB48SjPZrOqEn-wawob+GfKQrwLouyNP_zoPW_5QsvFFw@mail.gmail.com>
References: <[email protected]>
	<CANzqJaB48SjPZrOqEn-wawob+GfKQrwLouyNP_zoPW_5QsvFFw@mail.gmail.com>



On 6/12/24 15:48, Ron Johnson wrote:
> On Wed, Jun 12, 2024 at 5:28 PM Rich Shepard 
> <[email protected]> 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 <http://a.pk; = b.pk <http://b.pk;
>   AND b.field3 = mumble;
>
> (You can join them, right?)
Add "begin;" to that and try it.  If you don't get exactly UPDATE 295 
reported, then "rollback;";


view thread (4+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: UPDATE with multiple WHERE conditions
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox