Skip to main content
100%

upsert the_geom with security definer

✓ Published0🌍 Public
Aandrewxhill
Last edited Jun 21, 2013
Created on Jun 21, 2013

This example shows a PostgreSQL function that upserts geometry data for a Leaflet-based mapping application. It accepts parallel arrays of CartoDB IDs and GeoJSON strings, then returns operation codes (insert, update, delete) with corresponding cartodb_ids. The function uses PL/pgSQL with SECURITY DEFINER privileges to build a dynamic SQL query that performs updates, deletes, and inserts against the `leaflet_data` table. It leverages PostGIS functions `ST_SetSRID` and `ST_GeomFromGeoJSON` to convert GeoJSON into spatial geometries, while handling null values to trigger deletion.

AI-generated description

Similar vizzes