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.
1 Answer
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.
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.