public inbox for [email protected]
help / color / mirror / Atom feedFrom: Ray O'Donnell <[email protected]>
To: Rich Shepard <[email protected]>
To: [email protected]
Subject: Re: Updating 457 rows in a table
Date: Sun, 19 May 2024 17:57:41 +0100
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
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
[email protected]
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Updating 457 rows in a table
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox