Pages

Wednesday, November 18, 2020

Strangely beautiful SQL UPDATE (PostgreSQL 12)

When you need to fill data to null fields of multiple records, you had better avoid UPDATE. Rather:

  1. Prepare for a table to insert all the data to fill
  2. Use SELECT ~ OUTER JOIN to join with the original table
  3. And prepare for the "result" table to push the JOINed results via INSERT INTO.

I found out that I could finish the job in 5:35 when traditional UPDATE didn't finish in 10 minutes.

Tested under PostgreSQL 12.


No comments:

Post a Comment