I’ve got a simple ODK form with 1 repeat group, and am trying to map this to PostGres with little success.
Please could you have a look and see if you can pick up where I am going wrong?
Input (from ODK via JSON publisher):
{ "token": "", "formVersion": "", "formId": "phenology001", "data": [ { "today": "2019-08-26", "start": "2019-08-26T21:09:48.420Z", "observation": [ { "stage": "1", "picture": { "url": "https://<mypictureurl>", "type": "image/jpeg", "filename": "1566853816709.jpg" }, "notes": "Test note" }, { "stage": "2", "picture": { "url": "https://
", "type": "image/jpeg", "filename": "1566853849716.jpg" }, "notes": "Test note 2" } ], "name": "Andrew", "location:Longitude": null, "location:Latitude": null, "location:Altitude": null, "location:Accuracy": null, "instanceID": "uuid:f38ecef5-117a-44b3-a443-7d7d3b1ad3a6", "imei": "867440036085345", "end": "2019-08-26T21:11:03.306Z", "date": "2019-08-26", "*meta-ui-version*": null, "*meta-submission-date*": "2019-08-26T21:11:21.838Z", "*meta-model-version*": null, "*meta-is-complete*": true, "*meta-instance-id*": "uuid:f38ecef5-117a-44b3-a443-7d7d3b1ad3a6", "*meta-date-marked-as-complete*": "2019-08-26T21:11:21.838Z" } ], "content": "record", "__query_params": {} }
Job:
each( dataPath("data[*]"), combine( sql( function(state) { return (
INSERT INTO log_entry (odk_instance_id, logger_name) VALUES (’`
- dataValue(“meta-instance-id”)(state) +
', '
- dataValue(“name”)(state) +
');
)}) ,
each(
dataPath(“observation[*]”),
sql( function(state) { return (
INSERT INTO log_entry_observation
(odk_instance_id, stage, notes) VALUES ('
-
123
+',
- dataValue(“stage”)(state) +
, '
- dataValue(“notes”)(state) +
')
)})
)
)
);
`
Job run output:
Executing SQL statement: INSERT INTO log_entry (odk_instance_id, logger_name) VALUES ('uuid:f38ecef5-117a-44b3-a443-7d7d3b1ad3a6', 'Andrew'); Executing SQL statement: INSERT INTO log_entry_observation (odk_instance_id, stage, notes) VALUES ('123', 1, 'Test note') Finished.
2 problems:
- Why is there only 1 log_entry_observation insert statement executed?
I expected the second each to trigger twice for the 2 repeats submitted
- The result of the job run was no change to my Postgres database (no rows inserted in either table).
Copy-pasting these statements and running them against the DB created both records successfully, so the SQL is correct.
Also, an initial simple job ignoring the repeats sucessfully inserted a row in thelog_entry
table, so I know the credentials are setup correctly.
Any ideas?
Is there any issue with using combine and sql together?
- Bonus question :o) How do I access/create a unique id for the repeat-group records? e.g. something like <parent_uuid>/observation[1]
Thanks!
Andrew