Skip to content

Instantly share code, notes, and snippets.

@dadair-ca
Last active August 11, 2019 07:37
Show Gist options
  • Save dadair-ca/f9d9dcfcdfbfacf9bf5f17094560d647 to your computer and use it in GitHub Desktop.
Save dadair-ca/f9d9dcfcdfbfacf9bf5f17094560d647 to your computer and use it in GitHub Desktop.
WITH inserted AS (
SELECT fhir_create_resource(:resource) AS resource -- should end up inserting into `encounter` table
), joined_foo AS (
INSERT INTO foo(x) SELECT resource->'id' FROM inserted
RETURNING *
), joined_bar AS (
INSERT INTO bar(x) SELECT resource->'id' FROM inserted
RETURNING *
) SELECT resource FROM inserted;
-- foo.x references encounter(id)
-- bar.x references encounter(id)
-- query complains that insert into foo(x) and bar(x) fails with foreign key violation (encounter record not in encounter table)
-- which seems to suggest that the `SELECT fhir_create_resource(:resource) AS resource` isn't actually inserting into the `encounter` table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment