Skip to main content
100%

Gist f2c843666c84195a872efebcc21f1f9f

✓ Published0🌍 Public
TThomasG77
Last edited Sep 25, 2021
Created on Sep 25, 2021

This PyQGIS script exports the column metadata of an active PostgreSQL layer to a CSV file. It shows the structure of every column, including data type, nullability, precision, defaults, and comments from the `information_schema.columns` view. Working within QGIS, it uses `QgsProviderRegistry` to create a PostgreSQL connection, executes the query via `executeSql`, sanitizes null `QVariant` values, and writes the results with Python’s `csv` module. The final CSV file is then added back to the map as a vector layer.

AI-generated description

Similar vizzes