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 1sHVZd-008Pe3-9G for pgsql-general@arkaria.postgresql.org; Wed, 12 Jun 2024 21:32:05 +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 1sHVZb-007UY7-2k for pgsql-general@arkaria.postgresql.org; Wed, 12 Jun 2024 21:32:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sHVZa-007UXe-KR for pgsql-general@lists.postgresql.org; Wed, 12 Jun 2024 21:32:03 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sHVZY-00116Z-AX for pgsql-general@lists.postgresql.org; Wed, 12 Jun 2024 21:32:02 +0000 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-52c32d934c2so395453e87.2 for ; Wed, 12 Jun 2024 14:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitnine-net.20230601.gappssmtp.com; s=20230601; t=1718227918; x=1718832718; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=7dI5hyMFst+kSlfkifP1N13byDCUJys2oEj2thwVU/0=; b=kL7QyThQaWbS1+4eG2dvjx4Uqg07N3SIwpY0pgRta0WiB9wzONJ0+n6lQNrxQ1iutT ZDZ9v0qmnZELH3K/UsQX0KzrEDsdF/q/pxXir0voa4SGOrT2ozCalQe6qmabKX47qnLi 7ZHhL20tpwkpSPxtAosZsevqclIFR/OwUSmTPgKkR/8uCwqo283MU70unDBg3RoyCPDD mQJH7kQxlr8KWIG5a7N46aijzfq+YyuBIDXjpCNCAg61opqH7t22hn2Eaok+Gu5IFbpc ia27P8LHg2Mqid6VbDipKoQhah3ZJb+PiD1siyojaz1cq6Y/HxFnbayC7VBn2RCUup4/ WvRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718227918; x=1718832718; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7dI5hyMFst+kSlfkifP1N13byDCUJys2oEj2thwVU/0=; b=D6sMaJRN8HFKYCO2F/76rhZYTh1q913SL+bmLTOb9ZGvUcvs7U1UBbhacorO11KClr 53og5fsUlxnRu11PlSnE4MMmQFDrS1oriFpDxpMnohIZV7QtTa7xZZM8X4MiS4wBjUdV PlYpKUdTj4ypqAOyWVdxf0/sNUVdCT60fRBooUYTXuWO0TjyddwJnBSqfv3AY6Cx/AJA 0tDB0FNEX2pKD7izc0P+HBCuE03F/zTeRTFEcPC+2gj4PhEaRTyhmsDC2cC5HIqbzIdQ 11Q+PZNh4HbtCzdZylmZQ2GtVthR+IaicZ/72jCzbSZMRi8RjcfHq+ZA9s6pM8Oy9joK oVzA== X-Gm-Message-State: AOJu0YwGcwSp3rydpvrK9iMQrqX7jh3x5sPJS0vnTfOFc5BEeMNtdHJ9 9jhkWugr4p0q5CZ0NNk8XXsy4aEORbq9IVyfO9sJT7T6OqO8fBNa48caExuOPy6rDKktQoLe1hp 9wFxbJq8Z3p6AOy5Fiwdkiaz2am5aGOBMB1pSqCGRCEl7vrnWazMNfg== X-Google-Smtp-Source: AGHT+IFixEJE9NA9DTb3EcIvR+otYEkX4pivg/V0tDJQEKvESffz1vtDsvgJkIEWATvRueAvzr//9DTUjf0IybjJZrE= X-Received: by 2002:a05:6512:3b9c:b0:52c:86d6:e8d7 with SMTP id 2adb3069b0e04-52c9a3b97bfmr2489039e87.13.1718227917647; Wed, 12 Jun 2024 14:31:57 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Muhammad Salahuddin Manzoor Date: Thu, 13 Jun 2024 02:31:43 +0500 Message-ID: Subject: Re: UPDATE with multiple WHERE conditions To: Rich Shepard Cc: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000acd3d6061ab81cc8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000acd3d6061ab81cc8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Greetings, You can use Temporary table. You could create a temporary table with one column containing the condition values and then use it to update your main table. This approach can be more flexible and cleaner than writing a script with multiple update statements. -- Create a temporary table with one column containing the condition values CREATE TEMPORARY TABLE temp_conditions (condition_value TEXT); -- Insert the condition values into the temporary table INSERT INTO temp_conditions (condition_value) VALUES ('value1'), ('value2'), ('value3'), -- Add more values as needed... ('value295'); -- Update the boolean column based on the condition values UPDATE your_table SET boolean_column =3D true WHERE condition_column IN (SELECT condition_value FROM temp_conditions); -- Clean up: drop the temporary table DROP TABLE IF EXISTS temp_conditions; *Salahuddin (=EC=82=B4=EB=9D=BC=ED=9B=84=EB=94=98**)* On Thu, 13 Jun 2024 at 02:28, 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, shou= ld > 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? > > TIA, > > Rich > > > --000000000000acd3d6061ab81cc8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Greetings,

You can use Temporary table.= You could create a temporary table with one column containing the conditio= n values and then use it to update your main table. This approach can be mo= re flexible and cleaner than writing a script with multiple update statemen= ts.

-- Create a temporary table with one column containing the condi= tion values
CREATE TEMPORARY TABLE temp_conditions (condition_value TEXT= );

-- Insert the condition values into the temporary table
INSERT= INTO temp_conditions (condition_value) VALUES
=C2=A0 =C2=A0 ('value= 1'),
=C2=A0 =C2=A0 ('value2'),
=C2=A0 =C2=A0 ('value3= '),
=C2=A0 =C2=A0 -- Add more values as needed...
=C2=A0 =C2=A0 (= 'value295');

-- Update the boolean column based on the condi= tion values
UPDATE your_table
SET boolean_column =3D true
WHERE co= ndition_column IN (SELECT condition_value FROM temp_conditions);

-- = Clean up: drop the temporary table
DROP TABLE IF EXISTS temp_conditions;=

=

<= font color=3D"#2255ff" face=3D"arial, sans-serif" size=3D"2">Salahuddin = (=EC=82=B4=EB=9D=BC=ED=9B=84=EB=94=98)



On Thu, 13 Jun 2024 at 02:28, Rich = Shepard <rshepard@appl-ecosy= s.com> wrote:
I have a table with 3492 rows. I want to update a boolean column from<= br> 'false' to 'true' for 295 rows based on the value of anothe= r 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?

TIA,

Rich


--000000000000acd3d6061ab81cc8--