1

This Query:

ALTER TABLE planet_osm_line ADD vertices FLOAT;
INSERT INTO planet_osm_line(vertices)
SELECT st_NPoints(way) FROM planet_osm_line;

does result in a empty column (NULL). What am I doing wrong?

1
ALTER TABLE planet_osm_line ADD COLUMN vertices INTEGER;

Why float? Are there fractional vertices?

You are also inserting records, when I think you actually want to update each way with the number of vertices within. Use an update function to add the values to the new column based on the result of the function operating on the spatial column. For example, try:

UPDATE planet_osm_line 
SET vertices = ST_NPoints(way) 
WHERE NOT ST_IsEmpty(way);
  • Great, it's working! The update function is the solution! – MAP Jan 22 '16 at 18:32
0

Looking into PostgreSQL Data Types Documentation it seems that there is no FLOAT data type. Try using numeric instead.

ALTER TABLE planet_osm_line ADD vertices numeric;
INSERT INTO planet_osm_line(vertices)
SELECT st_NPoints(way) FROM planet_osm_line;
  • 1
    "float" is an alias for "double precision" in PostgreSQL. – John Reiser Jan 22 '16 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.