3

I am trying to add some newly created columns to an existing table in PostGIS table from GeoPandas. Previously, I've pulled the data out of my database, run geocoding, and then created new columns from manipulating the results. I now want to update my table with these new columns, but running the to_postgis function with the if_exists=append option produces an psycopg2.errors.UndefinedColumn: column of relation does not exist. I assume this means that I need to do this via formatting an SQL statement and then executing it, but I was hoping there was some magic that would save me the trouble.

2
  • 3
    if_exists=append does not allow for the addition of new fields to a table, only new rows. You would need the field to exist within the table to have it work in the way you would want.
    – Joe Be
    Jan 14 at 10:35
  • 1
    That's correct - however ADD COLUMN statements are easy enough to run using Psycopg2 or SQLAlchemy
    – minus34
    Jan 17 at 5:00
1

Per @Joe Be's comment, it's necessary to either write a SQL statement to add the additional columns to the DB, or to do so manually before running the script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.