Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here are the steps you can take to rectify the issue of a corrupted geometry column caused by altering the Postgis Schema Name in QGIS:

  1. Connect to your PostGIS database using a SQL client, such as pgAdmin or psql.

  2. Create a backup of your database in case anything goes wrong during the following steps.

  3. Run the following SQL script to update the schema name of your spatial tables:

    ALTER TABLE <schema_name>.<table_name> SET SCHEMA <new_schema_name>;
    
  4. Run the following SQL script to update the SRID of your spatial tables:

    SELECT UpdateGeometrySRID('<new_schema_name>', '<table_name>', 'geom', <new_srid>);
    

    Replace <new_srid> with the SRID that you want to use for your geometry column.

  5. If you have any views that reference your spatial tables, update their definitions to use the new schema name:

    CREATE OR REPLACE VIEW <new_schema_name>.<view_name> AS
    SELECT <columns>
    FROM <new_schema_name>.<table_name>
    WHERE <condition>;
    

    Replace <columns> with the columns that you want to select and <condition> with the condition that you want to use to filter the rows.

  6. Finally, re-add the spatial tables to QGIS and verify that the geometry column is now working correctly.

If you are not comfortable performing these steps yourself, it may be best to seek the assistance of a qualified database administrator or GIS professional.