{"version":"1.0","type":"rich","title":"upsert the_geom with security definer","description":"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.","provider_name":"VizHub AI Studio","provider_url":"https://next.vizhub.com","html":"<iframe src=\"https://next.vizhub.com/viz/gist-5830570?mode=embed\" width=\"960\" height=\"500\" scrolling=\"no\" frameborder=\"1\"></iframe>","width":960,"height":500,"cache_age":3600}