I use PostGIS and I would like to add a new point to an existing MultiPoint using ST_Collect. The problem is that I got this error message:
ERROR: Geometry type (GeometryCollection) does not match column type (MultiPoint) CONTEXT: PL/pgSQL function inline_code_block line 10 at assignment SQL state: 22023
What do you think? What is wrong in my code? The first ST_Collect runs successfully, but the second one is not.
My code:
DO $$
<<first_block>>
DECLARE
geom Geometry (MultiPoint,0);
astext varchar;
BEGIN
geom=ST_Collect(geom,ST_Multi(ST_GeomFromText('POINT(1 4)')));
geom=ST_Collect(geom,ST_Multi(ST_GeomFromText('POINT(1 10)')));
SELECT ST_AsText(geom) INTO astext;
RAISE NOTICE '%',astext;
END first_block $$;
I tried with GeometryCollection instead of MultiPoint:
DO $$
<<first_block>>
DECLARE
geom Geometry (GeometryCollection,0);
astext varchar;
BEGIN
geom=ST_Collect(geom,ST_Multi(ST_GeomFromText('POINT(1 4)')));
geom=ST_Collect(geom,ST_Multi(ST_GeomFromText('POINT(1 10)')));
SELECT ST_AsText(geom) INTO astext;
RAISE NOTICE '%',astext;
END first_block $$;
And I've got this error:
ERROR: Geometry type (MultiPoint) does not match column type (GeometryCollection) CONTEXT: PL/pgSQL function inline_code_block line 9 at assignment SQL state: 22023
I tried with Multipoints too:
DO $$
<<first_block>>
DECLARE
geom Geometry (MultiPoint,0);
astext varchar;
BEGIN
geom=ST_Collect(geom,(ST_GeomFromText('MULTIPOINT(1 4)')));
geom=ST_Collect(geom,(ST_GeomFromText('MULTIPOINT(1 10)')));
SELECT ST_AsText(geom) INTO astext;
RAISE NOTICE '%',astext;
END first_block $$;
Error message:
ERROR: Geometry type (GeometryCollection) does not match column type (MultiPoint) CONTEXT: PL/pgSQL function inline_code_block line 10 at assignment SQL state: 22023
ST_Union
will help you keep your promises. – geozelot Mar 12 '20 at 13:12