2

I am trying to change the geometry of a PostGIS db from multipoint to point and using this expressions works quite well

SELECT (ST_Dump(the_geom)).geom AS the_POINT_geom
 FROM MULTIPOINT_table;

But when trying to add this as new column via

ALTER TABLE your_table ADD COLUMN the_POINT_geom double precision;
UPDATE your_table SET the_POINT_geom = (ST_Dump(geom)).geom;

this only causes an error:

set-returning functions are not allowed in UPDATE

Is there a way to add the point geometry as new column?

geozelot
31.4k4 gold badges38 silver badges59 bronze badges
asked Aug 23, 2019 at 14:15
3
  • what's the error? Commented Aug 23, 2019 at 14:53
  • aggregate functions are not allowed in UPDATE or set-returning functions are not allowed in UPDATE [not exactly sure b/c error is given in german] Commented Aug 23, 2019 at 14:58
  • if you had an RECORD_ID you could use to re-join the data, you could build a new table of just the_point_geom and the record_id, then use that table to do the update instead of the aggregate function? Commented Aug 23, 2019 at 15:06

1 Answer 1

1

An UPDATE is a per-row operation and cannot expand the table. ST_Dump returns a SETOF RECORD which cannot be mapped to a single row directly (you can expand a SET within a subquery or CTE and return/join a single row from there), even if your MultiPoint actually consists of only one point geometry!

If that is indeed the case, you can extract that point and UPDATE the column:

UPDATE your_table
 SET the_POINT_geom = ST_GeometryN(geom, 1)
;

or, to keep only the initial column:

ALTER TABLE your_table
 ALTER COLUMN geom TYPE GEOMETRY(POINT, <SRID>)
 USING ST_SetSRID(ST_GeometryN(geom, 1), <SRID>)
;

If your MultiPoint consists of more than one point geometry, and you want to expand all of them into a table, you will need to create a new one using e.g. your SELECT query.

answered Aug 23, 2019 at 15:26
2
  • Alright, got it. I now solved it by creating a new table and joining the data via id number, but probably your solution will do the job more elegant as my multipoint object indeed consists of only one point each Commented Aug 23, 2019 at 15:32
  • @JWW It will...,) Try it, and consider accepting, so that others get the idea, too. Commented Aug 23, 2019 at 19:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.