example basic function - Giswater/giswater_dbmodel GitHub Wiki

-- For function code use any number of 4 DIGITS starting with '9'. It is reserved for you!!!! -- FUNCTION CODE: 9280 CREATE OR REPLACE FUNCTION "ud_sample".user_fct_mybasicfunction(p_data json) RETURNS json AS $BODY$

-- Here you can define the example call for your function. Very usefull to debug and to maintenance the code /*EXAMPLE SELECT user_fct_mybasicfunction($${ "client":{}, "form":{}, "feature":{}, "data":{ "parameters":{"arcId":"2001"}}}$$)::text */ DECLARE --Definition of all the variables used in the function v_arc_id text;-- We recomend to use v_* to define all variables to prevent conflicts with columnnames and tablenames BEGIN -- Search path - definition of schema in which the function will execute all the processes SET search_path = "ud_sample", public; -- Getting input data from the input json v_arc_id := ((p_data ->>'data')::json->>'parameters')::json->>'arcId'; --Computing process UPDATE arc SET the_geom = St_Reverse (the_geom) WHERE arc_id = v_arc_id; --Return - create return RETURN ('{"status":"Accepted", "message":{"level":1, "text":"Analysis done successfully"}'|| ',"body":{"form":{}'|| ',"data":{}}'|| '}')::json; END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100;