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 1s8jr3-00ExYc-WE for pgsql-general@arkaria.postgresql.org; Sun, 19 May 2024 16:57:52 +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 1s8jr4-00DOmv-0Z for pgsql-general@arkaria.postgresql.org; Sun, 19 May 2024 16:57:50 +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 1s8jr3-00DOmn-JT for pgsql-general@lists.postgresql.org; Sun, 19 May 2024 16:57:49 +0000 Received: from srv01.teladesign.ie ([2001:41c9:1:41d::10]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s8jr0-0013aH-8p for pgsql-general@lists.postgresql.org; Sun, 19 May 2024 16:57:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rodonnell.ie; s=exim; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: From:References:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To:Cc: Content-ID:Content-Description:Resent-Message-ID; bh=EspHekyRRNly1vT0WegDcspo9uaaxvNaobCOtcMwYAI=; b=df85vmnSIQn3xIPvBqjfigxAV+ 1KI/Yn6ObM9urge1KhFUdJ37cbBtdGjMs6tMxfKGF+RLe5sFLoq5xbIw4VB+vehq5+03oAgQntrLR zlsOfxo2OGzBRsioDOWI5aAr7jRMO3dschZoTgD6Amww2z3pkb6Ovzp8e2EWD464GeJc=; Received: from [51.37.105.39] (helo=[192.168.1.162]) by srv01.teladesign.ie with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1s8jqw-0002Wk-8L; Sun, 19 May 2024 17:57:44 +0100 Message-ID: <4001d2f9-1a70-47e5-9f21-754a5d7497bf@rodonnell.ie> Date: Sun, 19 May 2024 17:57:41 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Updating 457 rows in a table To: Rich Shepard , pgsql-general@lists.postgresql.org References: <164b3681-7a42-1e5-6a7b-80196ed33ded@appl-ecosys.com> Content-Language: en-GB From: Ray O'Donnell In-Reply-To: <164b3681-7a42-1e5-6a7b-80196ed33ded@appl-ecosys.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 19/05/2024 17:54, Rich Shepard wrote: > Searching the postgresql doc for UPDATE the examples I find show updating > one or a few rows in a table. I have 457 rows to update in a table. > > I could write a .sql script with 457 lines, each updating one row of the > table. My web search for `sql: update table rows from a file of column > values' finds pages for single row updates and updating a table from > another > table, but neither is what I want. > > I want to change a column value in a table based on the value of a > different > column in that same table. > > Specifically, in the 'people' table I want to change the column 'active' > from false to true for 457 specific person_id row numbers. > > Is there a way to do this without manually writing 457 'update ...' > rows in > a .sql file? Could you create a table with just person_id values whose rows are to be updated? Then you could do something like this: update people set active = true where exists (   select 1 from temporary_table where person_id = people.person_id ); That's just off the top of my head and might not be correct, but that's the way I'd be thinking. Ray. -- Raymond O'Donnell // Galway // Ireland ray@rodonnell.ie