0

I have an error in syntax @ in my code in postgreSQL database, but I don't know what could be wrong. Did I implemented the SQL loop code in rigth way? My SQL code:

DECLARE @Counter INT 
SET @Counter=1
WHILE ( @Counter <= 1000)
BEGIN
   INSERT INTO punkty (geog) SELECT ST_GeometryN(st_asText(ST_GeneratePoints(geom,1000)), @Counter) FROM panstwo
   SET @Counter  = @Counter  + 1
END
0

1 Answer 1

2

First your code looks like T-SQL(Microsoft and Sybase dialect) and it won't work on PostgreSQL by design

Second loop is not required:

INSERT INTO punkty (geog)
SELECT ST_GeometryN(st_asText(ST_GeneratePoints(geom,1000)), s.Counter) 
FROM panstwo
CROSS JOIN generate_series(1,1000) s(counter);
Sign up to request clarification or add additional context in comments.

1 Comment

thank you! But the function is generating 1000 random elements in every time when counter encreaseS. Do you know how to generate 1000 points once and then INSERT every point (1000 points) using this loop?

Your Answer

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.