0

I am getting stuck while executing the function,Function is getting created but while i am passing the values getting error.

CREATE OR REPLACE FUNCTION INS_CCX_ply(P_ID INTEGER,P_POLY_ID INTEGER,P_POLY POLYGON)
RETURNS voiD AS
 $BODY$
BEGIN
INSERT INTO CCX_poly(id,poly_id,poly) values(P_ID,P_POLY_ID,P_POLY);
END;  
 $BODY$
LANGUAGE plpgsql;  

SELECT * FROM INS_CCX_PLY(1,11,'point((1,1),(8,6),(6,8),(10,9),(1,1))');

2 Answers 2

1

You can convert a text into geometry with GeomFromText:

GeomFromText('POINT(-126.4 45.32)')

The simplest way to do it is modify your function to accept a text string and then convert the string into a geometry from inside your function. Then, pass the polygon to your INSERT statement.

1

In postgis there is no POLYGON type (see PostGIS Types).

There is a geometry type that has subtypes for points, lines, polygons and composed geometries (multiline, multipolygon, etc):

osm=# select 'POLYGON((26 44, 26 45, 27 45, 27 44, 26 44))'::geometry;
      geometry                                                                                          
 -----------------------
 010300000001000000050000000...

osm=# select st_asewkt('POLYGON((26 44, 26 45, 27 45, 27 44, 26 44))'::geometry);
                st_asewkt                 
------------------------------------------
 POLYGON((26 44,26 45,27 45,27 44,26 44))

(1 row)

Your Answer

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

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