Skip to content

Instantly share code, notes, and snippets.

@bmcbride
Forked from andrewxhill/polygon_insert.sql
Created December 4, 2015 21:28
Show Gist options
  • Save bmcbride/307e375b64a6e6e2f5cf to your computer and use it in GitHub Desktop.
Save bmcbride/307e375b64a6e6e2f5cf to your computer and use it in GitHub Desktop.
Polygon insert Named Function
-- Create a function withn the security set to Definer so that it can insert
CREATE OR REPLACE FUNCTION AXH_NewMinneapolis(integer, geometry) RETURNS integer
AS 'INSERT INTO minneapolis (parent_id, the_geom) (SELECT id, geom FROM (SELECT $1 id,$2 geom) a WHERE ST_NPoints(geom) < 100) RETURNING cartodb_id;'
LANGUAGE SQL
SECURITY DEFINER
RETURNS NULL ON NULL INPUT;
--Grant access to the public user
GRANT EXECUTE ON FUNCTION AXH_NewMinneapolis(integer, geometry) TO publicuser;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment