0

I have a table in the database called parts. The table looks like this and contains 3000 items:

Part_id    part_name    description    weight    price
1          book         drama                    11
5          pencil       blue                     5

There is no weight available for any item. But I just received an updated Excel file which has weights for each parts as well, the rest of data is the same as uploaded data in database. How can I update the weight column in the database?

An easy approach is to upload the new Excel file and forget the previous one available in the db but it is not very easy to upload because of the complexity of data and mapping needs to be done before data upload.

Thanks in advance.

Sana
  • 463
  • 2
  • 4
  • 22
  • The ID is also part of the Excel sheet? – sticky bit Sep 24 '18 at 09:10
  • 1
    The typical approach is to import the Excel data into a staging (temporary) table, then update the real table from there. –  Sep 24 '18 at 09:11
  • @stickybit yes it is a unique ID – Sana Sep 24 '18 at 09:12
  • @a_horse_with_no_name thanks could you help me more please?Probably a link to read? – Sana Sep 24 '18 at 09:13
  • @Saba: Then you can go the way a_horse_with_no_name suggests: Upload the file into a staging table and update the real table from the staging table via the ID. – sticky bit Sep 24 '18 at 09:15
  • @Saba - here is how you can update one table from another: https://stackoverflow.com/questions/7869592/how-to-do-an-update-join-in-postgresql – Oto Shavadze Sep 24 '18 at 09:16
  • @OtoShavadze Thank you, the solution does not work for me as the second table is not uploaded in the database and is just an excel sheet. – Sana Sep 24 '18 at 09:53

0 Answers0