Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sHW63-008W4a-NC for pgsql-general@arkaria.postgresql.org; Wed, 12 Jun 2024 22:05:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sHW61-008Gil-Hq for pgsql-general@arkaria.postgresql.org; Wed, 12 Jun 2024 22:05:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sHW61-008GYQ-2c for pgsql-general@lists.postgresql.org; Wed, 12 Jun 2024 22:05:33 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sHW5y-001ME0-Ua for pgsql-general@lists.postgresql.org; Wed, 12 Jun 2024 22:05:33 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1f4a0050b9aso3523565ad.2 for ; Wed, 12 Jun 2024 15:05:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718229928; x=1718834728; darn=lists.postgresql.org; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=n0sPaXrmPFzKLOjOavIb/6xClyksOj4uW8Az0AonZ/g=; b=nbz9Sum83dUr5nG1CgsHSPVNpJ5nkWoR/V9h5cONt66SFJn8wYVrykKqgsaogjGShv 2OtRMxmtUEIZcZZqrvWESfddUXQY/PPTOcqUkzy7r//pa5hG+cqbwFdIyfJM84SekQ4S I7eUX9oFpSU86Tl4mzJEJRBAztpBq1x9yYn+bD4OcoDBz7GK0HErCoGMTicUIGY4WBvN z5UFF8S53nfkvrp2tczNdQ6L69bSWqZknJBilmPWyh/NhkjMG0RyGx3TkWnGOtON/ZWc cT/GCa+zgy2tYvkdK7fusOGPCw6lQj5jfneELJkCZe6XNdtivYO1NnvUsDTei6HTR9x/ dLhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718229928; x=1718834728; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=n0sPaXrmPFzKLOjOavIb/6xClyksOj4uW8Az0AonZ/g=; b=QmNKUHNMH+N7grEwEDtDZ+/tsqlhsWB6A8S+lhYcSEQndqL4bpRzKy4MKZlNknIlrR vhWfQ2QvnHQehXG6VTuq6Iwljan7fcjQwU6kd2O4dMThvrlb8u1mKKr1zpD0IJrp5JLb vm2B4yZKSUVChRLmA6qK4kSu15Ktc3SX/k0skaBYi4SboMg3q6NuTSsHt2X+vllS+f7Q SZafncwU+QLr/W/Wrpy7OF7+8EG7EZue00AKZw/zdxL7eK0N8dg+1rN6JiAvtw3+syud zag6eAzejwwJ/15nRfBBw6U+1lZ71Bd7X03M1Ug6xEh8RZJbijzs6Z+qmqz5wJzLiReq EvHg== X-Gm-Message-State: AOJu0YwCOjjvmyIquUjg3m/1T598KWS319f7OwWIzv2NL4A1evZHFPBo Hi67VKBBwM20mXFdcP79Tx0h9w1Hxc2EdZhxiRq1JrMxFTTpISWsp3b8yQ== X-Google-Smtp-Source: AGHT+IEW89O9BuMajnL2ttdLUsEQk+H+7NAOyeO2OC2EMaNCM8k6Xz0irl/V0tGWNL71Kq3IfCAPEQ== X-Received: by 2002:a17:902:d506:b0:1f4:b7ff:ac41 with SMTP id d9443c01a7336-1f83b601677mr39736105ad.36.1718229927541; Wed, 12 Jun 2024 15:05:27 -0700 (PDT) Received: from [192.168.1.3] (c-76-140-27-218.hsd1.ut.comcast.net. [76.140.27.218]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f73fd3ee79sm30163555ad.300.2024.06.12.15.05.26 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Jun 2024 15:05:27 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------B4NHV0EmI8zknL96jFzTp1eC" Message-ID: <2587edf4-cd3e-46bd-8203-2881fc3902e9@gmail.com> Date: Wed, 12 Jun 2024 16:05:26 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: UPDATE with multiple WHERE conditions To: pgsql-general@lists.postgresql.org References: Content-Language: en-CA From: Rob Sargent In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------B4NHV0EmI8zknL96jFzTp1eC Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 6/12/24 15:48, Ron Johnson wrote: > On Wed, Jun 12, 2024 at 5:28 PM Rich Shepard > 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?) Add "begin;" to that and try it.  If you don't get exactly UPDATE 295 reported, then "rollback;"; --------------B4NHV0EmI8zknL96jFzTp1eC Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

On 6/12/24 15:48, Ron Johnson wrote:
On Wed, Jun 12, 2024 at 5:28 PM Rich Shepard <rshepard@appl-ecosys.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?)
Add "begin;" to that and try it.  If you don't get exactly UPDATE 295 reported, then "rollback;";

--------------B4NHV0EmI8zknL96jFzTp1eC--