CREATE VIEW - Geometrycollection - Empty Table

Hello PostGIS Community,

I have a Problem. I have a table with a geometry collection (polygon and point).
QGIS can not read the geometry collection, so I want to create a view for the polygon type and the point type. My SQL function for the polygon type looks like this:

CREATE VIEW parcel_polygons AS (
SELECT
row_number() OVER(ORDER BY inspire_local DESC) AS OID
, inspire_local
, inspire_namespace
, label
, nationalcadref
, areavalue
, validfrom
, beginlifespanversion
, zoning
, geom::geometry(Polygon, 25833)
FROM cp_parcel_postgis
WHERE GeometryType(geom) = ‘GEOMETRYCOLLECTION(POLYGON)’
)

I do not get any errors and the view is created. Unfortunately, the view is empty.
What am I doing wrong?

Thanks for any help,
Oli

did the query returns any records? Btw, OID is a reserved word, rename it, maybe that’s the problem.

And yes: this is a german-speaking forum, can we switch to german please?

Hallo akretschmer,

vielen Dank für deine schnelle Antwort. Ich habe das Problem realtiv gelöst mit ST_Dump.

CREATE VIEW parcel_polygons_view AS (
SELECT
row_number() OVER(ORDER BY inspire_local DESC) AS OID
, inspire_local
, inspire_namespace
, label
, nationalcadref
, areavalue
, validfrom
, beginlifespanversion
, zoning
, (st_dump(geom)).geom as geom
FROM ´
WHERE GeometryType(geom) = ‘GEOMETRYCOLLECTION’
)

Jedoch habe ich nun das Problem, dass ich in meiner geom Spalte des Views Geometrietypen Polygon und Point sind und meine ID Spalte (OID) sich die Ziffern doppeln. Wenn ich die Zeilen löschen könnte, wäre das Problem gelöst. Doch wie lösche ich Zeilen in einem View?

Leider hat die folgende Erstellung einer Regel nicht zum erfolg geführt:

CREATE RULE point_delete AS ON DELETE TO parcel_polygons_view DO INSTEAD(
DELETE FROM parcel_polygons_view WHERE GeometryType(geom) = ‘POINT’;
);

Kannst du mir da weiterhelfen?

Das Problem hat sich gelöst durch folgende Funktion:

CREATE VIEW parcel_polygons AS (

SELECT
polys_and_points.*
FROM
(SELECT
row_number() OVER(ORDER BY inspire_local DESC) AS OID
, inspire_local
, inspire_namespace
, label
, nationalcadref
, areavalue
, validfrom
, beginlifespanversion
, zoning
, (ST_dump(geom)).geom
FROM cp_parcel_postgis) as polys_and_points
WHERE
st_geometrytype(polys_and_points.geom) = ‘ST_Polygon’
)

Trotzdem Danke für jegliche Unterstützungsbereitschaft :slight_smile: