How-to loop over JSON Arrays in postgresql 9.3

I'm writing function for a new postgreSQL db and i'm trying to loop over a nested structure.

Is that even possible with the new JSON functions? What i'm trying to do is here below:

DO
$BODY$
DECLARE
    omgjson json := '[{ "type": false }, { "type": "photo" }, {"type": "comment" }]';
    i record;
BEGIN
  FOR i IN SELECT * FROM json_array_elements(omgjson)
  LOOP
    RAISE NOTICE 'output from space %', i;
  END LOOP;
END;
$BODY$ language plpgsql

This returns a set of records (text!), that is not JSON! so i cannot query it like i->>'type', but that's exactly what i want to accomplish...

Answers


I was a little dumb, but the documentation on this json feature on postgresql website is actually minimal

to solve the problem all i did was

DO
$BODY$
DECLARE
    omgjson json := '[{ "type": false }, { "type": "photo" }, {"type": "comment" }]';
    i json;
BEGIN
  FOR i IN SELECT * FROM json_array_elements(omgjson)
  LOOP
    RAISE NOTICE 'output from space %', i->>'type';
  END LOOP;
END;
$BODY$ language plpgsql

Need Your Help

Entity Framework - Cannot convert lambda expression to type 'string' because it is not a delegate type

c# .net entity-framework lambda

I am using Entity Framework in my C# based code. I am running into an unexpected weirdness and am looking for suggestions.

How to create a centered UICollectionView like in Spotify's Player

ios objective-c uiscrollview uicollectionview uicollectionviewlayout

I am have a lot of difficulty trying to create a UICollectionView like in Spotify's Player that acts like this: