public inbox for [email protected]  
help / color / mirror / Atom feed
Re: UPDATE with multiple WHERE conditions
4+ messages / 3 participants
[nested] [flat]

* Re: UPDATE with multiple WHERE conditions
@ 2024-06-12 21:48 Ron Johnson <[email protected]>
  2024-06-12 22:05 ` Re: UPDATE with multiple WHERE conditions Rob Sargent <[email protected]>
  2024-06-12 22:46 ` Re: UPDATE with multiple WHERE conditions Rich Shepard <[email protected]>
  0 siblings, 2 replies; 4+ messages in thread

From: Ron Johnson @ 2024-06-12 21:48 UTC (permalink / raw)
  To: pgsql-general

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 = b.pk
  AND b.field3 = mumble;

(You can join them, right?)


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: UPDATE with multiple WHERE conditions
  2024-06-12 21:48 Re: UPDATE with multiple WHERE conditions Ron Johnson <[email protected]>
@ 2024-06-12 22:05 ` Rob Sargent <[email protected]>
  2024-06-12 22:47   ` Re: UPDATE with multiple WHERE conditions Rich Shepard <[email protected]>
  1 sibling, 1 reply; 4+ messages in thread

From: Rob Sargent @ 2024-06-12 22:05 UTC (permalink / raw)
  To: [email protected]



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;";


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: UPDATE with multiple WHERE conditions
  2024-06-12 21:48 Re: UPDATE with multiple WHERE conditions Ron Johnson <[email protected]>
  2024-06-12 22:05 ` Re: UPDATE with multiple WHERE conditions Rob Sargent <[email protected]>
@ 2024-06-12 22:47   ` Rich Shepard <[email protected]>
  0 siblings, 0 replies; 4+ messages in thread

From: Rich Shepard @ 2024-06-12 22:47 UTC (permalink / raw)
  To: [email protected]

On Wed, 12 Jun 2024, Rob Sargent wrote:

> Add "begin;" to that and try it.  If you don't get exactly UPDATE 295
> reported, then "rollback;";

Got it, thanks.

Rich






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: UPDATE with multiple WHERE conditions
  2024-06-12 21:48 Re: UPDATE with multiple WHERE conditions Ron Johnson <[email protected]>
@ 2024-06-12 22:46 ` Rich Shepard <[email protected]>
  1 sibling, 0 replies; 4+ messages in thread

From: Rich Shepard @ 2024-06-12 22:46 UTC (permalink / raw)
  To: pgsql-general

On Wed, 12 Jun 2024, Ron Johnson wrote:

> 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?)

Thanks, Ron.

Rich






^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2024-06-12 22:47 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-06-12 21:48 Re: UPDATE with multiple WHERE conditions Ron Johnson <[email protected]>
2024-06-12 22:05 ` Rob Sargent <[email protected]>
2024-06-12 22:47   ` Rich Shepard <[email protected]>
2024-06-12 22:46 ` Rich Shepard <[email protected]>

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