CREATE TABLE parents ( parent_id bigserial PRIMARY KEY, "name" varchar NOT NULL UNIQUE ); CREATE TABLE children ( child_id bigserial PRIMARY KEY, "name" varchar NOT NULL UNIQUE, parent_id bigint NOT NULL REFERENCES parents(parent_id) ); CREATE OR REPLACE FUNCTION upsert_parent(parent json) RETURNS TABLE(parent json) AS $$ with parent_candidates AS ( -- 引数の JSON を非正規形のテーブルに変換 SELECT * FROM json_to_