PostGIS – Adding New Columns to Existing PostGIS Table from GeoPandas

geopandaspostgissql

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 by 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 a 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.

Best 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.