Created
August 9, 2015 14:00
-
-
Save rusllonrails/3e0c87514f1c2f9a19b0 to your computer and use it in GitHub Desktop.
POSTGRESQL | LOOP JSONB ARRAY
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
CREATE OR REPLACE FUNCTION test1(in_array jsonb) | |
RETURNS jsonb AS $$ | |
DECLARE | |
js jsonb := in_array; | |
i jsonb; | |
BEGIN | |
raise notice ' '; | |
raise notice 'js: %', js; | |
raise notice ' '; | |
raise notice 'jsonb_array_length(js): %', jsonb_array_length(js); | |
FOR i IN SELECT * FROM jsonb_array_elements(js) | |
LOOP | |
RAISE NOTICE '-----------------------------------'; | |
RAISE NOTICE 'uuid %', i->>'uuid'; | |
RAISE NOTICE 'state %', i->>'state'; | |
RAISE NOTICE 'version %', i->>'version'; | |
RAISE NOTICE 'expires_on %', i->>'expires_on'; | |
RAISE NOTICE 'issue_date %', i->>'issue_date'; | |
RAISE NOTICE 'updated_at %', i->>'updated_at'; | |
RAISE NOTICE 'category_id %', i->>'category_id'; | |
RAISE NOTICE '-----------------------------------'; | |
END LOOP; | |
RETURN js; | |
END; | |
$$ LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment