Skip to content

Instantly share code, notes, and snippets.

@BEULAHEVANJALIN
Last active August 17, 2023 08:53
Show Gist options
  • Save BEULAHEVANJALIN/4bd958a99c32eed5072123bb613333f1 to your computer and use it in GitHub Desktop.
Save BEULAHEVANJALIN/4bd958a99c32eed5072123bb613333f1 to your computer and use it in GitHub Desktop.
Remove off the questions from "Number of Participants" question group. #72
-- Select the data before the update
select observations ->> '2966afcc-2c07-44cf-8711-3fc23f52a6b5',
observations ->> '526b0d5d-51cc-4004-8c12-7a6c71c6c516',
observations ->> 'a043fea3-1658-4b5e-becd-ee55ab305a03',
observations ->> '1157c7c8-9f27-410d-9115-ef36191fba06'
from individual
where individual.organisation_id = (select id from organisation where name = 'Goonj Revamp');
-- Remove off all the questions from the "Number of Participants" question group.
update individual
set observations = observations || jsonb_build_object(
'2966afcc-2c07-44cf-8711-3fc23f52a6b5',
(observations -> '1157c7c8-9f27-410d-9115-ef36191fba06' ->> '2966afcc-2c07-44cf-8711-3fc23f52a6b5')::int,
'526b0d5d-51cc-4004-8c12-7a6c71c6c516',
(observations -> '1157c7c8-9f27-410d-9115-ef36191fba06' ->> '526b0d5d-51cc-4004-8c12-7a6c71c6c516')::int,
'a043fea3-1658-4b5e-becd-ee55ab305a03',
(observations -> '1157c7c8-9f27-410d-9115-ef36191fba06' ->> 'a043fea3-1658-4b5e-becd-ee55ab305a03')::int
),
manual_update_history = 'Breaking out all the questions from the "Number of Participants" question group.',
last_modified_by_id = (select id from users where username = 'beulah@gpart'),
last_modified_date_time = current_timestamp + ((individual.id % 1000) * interval '1 millisecond')
where individual.organisation_id = (select id from organisation where name = 'Goonj Revamp');
--Removing the "Number of Participants" question group.
UPDATE individual
SET observations = observations - '1157c7c8-9f27-410d-9115-ef36191fba06',
manual_update_history = 'Removing the "Number of Participants" question group.',
last_modified_by_id = (select id from users where username = 'beulah@gpart'),
last_modified_date_time = current_timestamp + ((individual.id % 1000) * interval '1 millisecond')
where individual.organisation_id = (select id from organisation where name = 'Goonj Revamp');
-- Verify the data after the update
select observations ->> '2966afcc-2c07-44cf-8711-3fc23f52a6b5',
observations ->> '526b0d5d-51cc-4004-8c12-7a6c71c6c516',
observations ->> 'a043fea3-1658-4b5e-becd-ee55ab305a03',
observations ->> '1157c7c8-9f27-410d-9115-ef36191fba06'
from individual
where individual.organisation_id = (select id from organisation where name = 'Goonj Revamp');
@himeshr
Copy link

himeshr commented Aug 16, 2023

Add offset for last_modified_date_time column value in both Update statements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment