0

I have a Postgres table publications that has a boolean column active, and my task was to set all the active values to FALSE, so I did the following copy command to have a backup of the rows that have an active value of TRUE:

\copy (SELECT publication_id FROM publications WHERE active = TRUE)
to '~/active_publications.csv'
with csv

In the end, I got a CSV file that has all the publication_ids of the active rows. Then I ran the following command to set all the active values to FALSE:

UPDATE publications SET active = FALSE;

Now I need to go back in a reverse process: How can I use this file to set the active values back to TRUE for all the rows that have a publication_id in this CSV file?

0

1 Answer 1

1

The simple way is to load the file with COPY into a temporary table and then use UPDATE ... FROM or INSERT ... ON CONFLICT to update your table.

Alternatively, you can use file_fdw to define the file as a foreign table and UPDATE using that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.