Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. SELECT name, json_array_elements(myjson)->>'id' id FROM
  2. (SELECT 'Dingsda'::text AS name, json_build_array('{"id" : 100}'::json, '{"id" : 200}'::json) myjson
  3. UNION ALL
  4. SELECT 'Dingsbums'::text AS name, json_build_array('{"id" : 101}'::json, '{"id" : 201}'::json, '{"id" : 301}'::json) myjson
  5. ) t;
  6.  
  7. +-----------+-----+
  8. | name | id |
  9. +-----------+-----+
  10. | Dingsda | 100 |
  11. | Dingsda | 200 |
  12. | Dingsbums | 101 |
  13. | Dingsbums | 201 |
  14. +-----------+-----+
  15.  
  16. +-----------+-----+-------+
  17. | name | id | index |
  18. +-----------+-----+-------+
  19. | Dingsda | 100 | 0 |
  20. | Dingsda | 200 | 1 |
  21. | Dingsbums | 101 | 0 |
  22. | Dingsbums | 201 | 1 |
  23. | Dingsbums | 301 | 2 |
  24. +-----------+-----+-------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement