Last active
May 28, 2016 23:12
-
-
Save ebachter/d0f6c0d692b1bacb2781df6bdfd839a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Function: public.delete_cunit(text, integer) | |
-- DROP FUNCTION public.delete_cunit(text, integer); | |
CREATE OR REPLACE FUNCTION public.delete_cunit( | |
IN cunit text, | |
IN modelid integer, | |
OUT x text, | |
OUT tt text, | |
OUT tt2 text) | |
RETURNS record AS | |
$BODY$ | |
DECLARE | |
tmpvar int; | |
myvar text; | |
BEGIN | |
select json_object_agg(key,value),json_agg(key) into tt,tt2 | |
from jsonb_each( | |
(select jsonb_extract_path(model,'states') from models where id=modelid) | |
) a where a.key<>cunit; | |
update models set labels = jsonb_set(labels, '{de_DE,units,cunit}', 'myvar'::jsonb, false) where id=modelid; | |
END; | |
$BODY$ | |
LANGUAGE plpgsql VOLATILE | |
COST 100; | |
ALTER FUNCTION public.delete_cunit(text, integer) | |
OWNER TO postgres; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment