Re: UPDATE with multiple WHERE conditions

Поиск
Список
Период
Сортировка
От Muhammad Salahuddin Manzoor
Тема Re: UPDATE with multiple WHERE conditions
Дата
Msg-id CAKD7CD=p9KZfB9u+A=p2-Eju1hkUGBnwJMg+xEk82K6wm3mcTA@mail.gmail.com
обсуждение исходный текст
Ответ на UPDATE with multiple WHERE conditions  (Rich Shepard <rshepard@appl-ecosys.com>)
Ответы Re: UPDATE with multiple WHERE conditions
Список pgsql-general
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 <rshepard@appl-ecosys.com> 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


В списке pgsql-general по дате отправления:

Предыдущее
От: Rich Shepard
Дата:
Сообщение: UPDATE with multiple WHERE conditions
Следующее
От: Rich Shepard
Дата:
Сообщение: Re: UPDATE with multiple WHERE conditions