Skip to content

Instantly share code, notes, and snippets.

@jatorre
Created January 13, 2013 17:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jatorre/4525165 to your computer and use it in GitHub Desktop.
Save jatorre/4525165 to your computer and use it in GitHub Desktop.
-- Create a function withn the security set to Definer so that it can insert
CREATE OR REPLACE FUNCTION cdb_insert_point(float, float) RETURNS integer
AS 'INSERT INTO example_table(the_geom) VALUES(ST_SetSRID(ST_MakePoint($1,$2),4326)) RETURNING cartodb_id;'
LANGUAGE SQL
SECURITY DEFINER
RETURNS NULL ON NULL INPUT;
--Grant access to the public user
GRANT EXECUTE ON FUNCTION cdb_insert_point(float,float) TO publicuser;
-- Call the new function like:
-- http://jatorre.cartodb.com/api/v1/sql?q=SELECT%20cdb_insert_point(8,8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment