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 1sHVpj-008Stj-37 for pgsql-general@arkaria.postgresql.org; Wed, 12 Jun 2024 21:48:43 +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 1sHVpg-007zU2-SU for pgsql-general@arkaria.postgresql.org; Wed, 12 Jun 2024 21:48:41 +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 1sHVpg-007zSu-I5 for pgsql-general@lists.postgresql.org; Wed, 12 Jun 2024 21:48:41 +0000 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sHVpe-0011Ea-Oa for pgsql-general@postgresql.org; Wed, 12 Jun 2024 21:48:40 +0000 Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3d2280a3d1fso147296b6e.3 for ; Wed, 12 Jun 2024 14:48:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718228918; x=1718833718; darn=postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=RO5PYyF1sw0Q0pIK4eKhWNGPOBSiFrYFP1gJk/v89bk=; b=QYTuOBWtDKZYp4mJYIhxqxIi/4hW38K8C4xvRog8HVbfIXysjAshpiwEEbrUQcypms dYJtGm8cX7cyDbryFZ+efbgCXsmJ8iA6F9ftiJ9S2LMF6rxfyMSK0DJWjGLGfJI9x7cz 2YW4MOtxVNl8xVin+YbgsqivAq2ofj8NanYGt0oUUIv6EWr4Wtk5Rut+ZRW1gnjZj7dj lQttvE13wrhocMaGZbZ7/Z8KoE5kmBrZo4g0wjE1qWoXKnO0ZqHcBSPa1oLQrPAwU3Dl fwFZoMwsP0lLQQC9RuOEsbRN1JmsVxketWgL67au78tqnc8lQE32kDwwuhEtp/0Y+UXc KY5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718228918; x=1718833718; h=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=RO5PYyF1sw0Q0pIK4eKhWNGPOBSiFrYFP1gJk/v89bk=; b=vdji4VpjUbqv61Sq0lNnhqAbEPpZju5J3I+p0fdz1UoZAsZZSBF3zozJylAAL+Tv9p 6oNP5J7LF0CKksdKV571VFadtgOGkOCBHMmCI6zWUuNAfV4pKSoPvpX4MXUj4/D4BbWK h1SNbN97ks0zwLYUz/1mBatceqT4YKVUBpJxYcKC2Mfz4KSXGxiIYsAa3U7d5rSwiv70 rPQ5aQZh2gsvsuuezV7xTD95VOXIjl2/AmsQxwt9yChi/4mEuorM2G+W5i7Xn0k6BsKw T16PKIr5VARkEm4Nx1geIxAnCnjj95dr91GdV0DXmzWbR/cQqwrXtU6GP88n4RhD66I8 MSIw== X-Gm-Message-State: AOJu0YzRhpNTK12ZvS+U7K6qL5oQrH9Hs9FTvzc9g2eJyNN6ZalSkfoM AZ8JlYpQuOcm+wAB+88g6ShUCPt1wk3x/DgwW0u2DQM/Gkj6yhZ8jvk2rzgc6giTk5Ucmiyz3J2 sIy+JhOAjnGIrQp/dBHZ9pJyjX2KO6A== X-Google-Smtp-Source: AGHT+IEwhWmpBMUywKcnOtNrJpU0wa+BT1YOl7xOgiwZXLaVUJU37ap1l1u7rUI5WIOTFYhVeB/+SJv6g0Clr4bOI44= X-Received: by 2002:a05:6870:65ac:b0:254:c397:8127 with SMTP id 586e51a60fabf-25514f48e53mr3079088fac.58.1718228917780; Wed, 12 Jun 2024 14:48:37 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ron Johnson Date: Wed, 12 Jun 2024 17:48:26 -0400 Message-ID: Subject: Re: UPDATE with multiple WHERE conditions To: pgsql-general Content-Type: multipart/alternative; boundary="000000000000498688061ab858d0" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000498688061ab858d0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jun 12, 2024 at 5:28=E2=80=AFPM 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? > A plain UPDATE might work. UPDATE to_be_updated a SET bool_col =3D true FROM other_table b WHERE a.pk =3D b.pk AND b.field3 =3D mumble; (You can join them, right?) --000000000000498688061ab858d0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, Jun 12, 2024 at 5:28=E2=80=AFPM R= ich Shepard <rshepard@appl-e= cosys.com> wrote:
I have a table with 3492 rows. I want t= o update a boolean column from
'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?

A plain=C2=A0UPDATE might work.=C2=A0=C2=A0
=C2=A0
UPDATE to_be_updated a
SET bool_col =3D true
<= div>FROM other_table b
WHERE a.pk =3D b.pk
=C2=A0 AND b.fiel= d3 =3D mumble;

(You can join them, right?)<= /div>
--000000000000498688061ab858d0--