public inbox for [email protected]
help / color / mirror / Atom feedRe: UPDATE with multiple WHERE conditions
2+ messages / 2 participants
[nested] [flat]
* Re: UPDATE with multiple WHERE conditions
@ 2024-06-12 21:31 Muhammad Salahuddin Manzoor <[email protected]>
2024-06-12 21:34 ` Re: UPDATE with multiple WHERE conditions Rich Shepard <[email protected]>
0 siblings, 1 reply; 2+ messages in thread
From: Muhammad Salahuddin Manzoor @ 2024-06-12 21:31 UTC (permalink / raw)
To: Rich Shepard <[email protected]>; +Cc: [email protected]
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 = true
WHERE condition_column IN (SELECT condition_value FROM temp_conditions);
-- Clean up: drop the temporary table
DROP TABLE IF EXISTS temp_conditions;
*Salahuddin (μ΄λΌνλ**)*
On Thu, 13 Jun 2024 at 02:28, Rich Shepard <[email protected]> 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?
>
> TIA,
>
> Rich
>
>
>
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: UPDATE with multiple WHERE conditions
2024-06-12 21:31 Re: UPDATE with multiple WHERE conditions Muhammad Salahuddin Manzoor <[email protected]>
@ 2024-06-12 21:34 ` Rich Shepard <[email protected]>
0 siblings, 0 replies; 2+ messages in thread
From: Rich Shepard @ 2024-06-12 21:34 UTC (permalink / raw)
To: [email protected]
On Thu, 13 Jun 2024, Muhammad Salahuddin Manzoor wrote:
> 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.
Salahuddin,
Thank you. I thought this would be the best approach.
Regards,
Rich
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2024-06-12 21:34 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-06-12 21:31 Re: UPDATE with multiple WHERE conditions Muhammad Salahuddin Manzoor <[email protected]>
2024-06-12 21:34 ` Rich Shepard <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox