Skip to content

Instantly share code, notes, and snippets.

@agilepoodle
Created July 5, 2017 05:40
Show Gist options
  • Save agilepoodle/baccc3260c3233d8cbfd11b2f0e576cb to your computer and use it in GitHub Desktop.
Save agilepoodle/baccc3260c3233d8cbfd11b2f0e576cb to your computer and use it in GitHub Desktop.
PostgreSQL jsonb operations
select id, jsonb_agg(selection_point - 'moduleId' - 'bottomSelectionPointParentId' ||
jsonb_build_object('moduleGroupId', (select group_id from module where id=selection_point->>'moduleId')))
into temporary education_vertical_top_selection_point_group_id
from (select id, jsonb_array_elements(document -> 'structure' -> 'vertical' -> 'topSelectionPoints')
as selection_point from education) tss group by id;
update education set document =
(jsonb_set(document, '{structure,vertical,topSelectionPoints}',
'[{"localId": "sis-group-deg-0001", "moduleId": "sis-deg-non-existent-v1", "bottomNaming": "NAMES_NOTHING", "topDegreeTitleUrn": null, "bottomAcceptanceType": "AUTOMATIC", "bottomSelectionPoints": [], "bottomSelectionPointParentId": null}]')
) where id = 'test-education-in-future';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment