0

I'm trying to import csv file's informations to PostgreSql using python.

The problem is When new informations are added from the beginning of number 1..., it needs to be continued where the database table's number stopped at.

For example. Last number is stopped at 300 in database table. And when I update excel file there will be new informations starting from number 1 again. It needs to be continued from 301 when new informations added. How can I achieve to this ? Please, help me.

  • You're looking to perform an UPSERT. Try this solution: https://stackoverflow.com/questions/61366664/how-to-upsert-pandas-dataframe-to-postgresql-table – Kelvin Ducray Dec 10 '21 at 09:28
  • But I don't want to update new informations. New informations row must be continued where the old table's row stopped at. For example last row was at 300 and when I add new csv file it needs to be continued from 301. – Anna Maria Dec 10 '21 at 09:52
  • Thats what an upsert does, if the data is already there it will leave it alone – Kelvin Ducray Dec 10 '21 at 09:58
  • Hmm, but it shouldn't leave it alone, anyway new data needs to be in the next row (301)... – Anna Maria Dec 10 '21 at 10:03
  • How can I do it ? – Anna Maria Dec 10 '21 at 10:03
  • If in the new csv file's row number is 1 put it after 300 and make it 301. And so on... – Anna Maria Dec 10 '21 at 10:06
  • UPSERT means to insert or update, suppose you run a query of the UPSERT, it checks with the primary field that the record exists or not. if not exists it will insert a new record and if already exists it will update the table fields' value. So, as you can see it doesn't needs to be updated. Instead it must continue from number 301. – Anna Maria Dec 10 '21 at 11:04
  • What's your table structure? In a [similar question a few hours ago](https://stackoverflow.com/q/70300199/372643), you said all your columns were text: does this row number come in as text, do you want to keep it as text? (It seems it would make more sense as an integer.) – Bruno Dec 10 '21 at 11:47
  • Okay, I will change it as integer. So what's next ? – Anna Maria Dec 10 '21 at 11:54

0 Answers0