Concept: a trigger what creates a new record in a table after a new JSON object has been created in another table. I don't want to make any modifications yet, just to "convert" JSON objects to records with a trigger.
Asked
Active
Viewed 781 times
1 Answers
4
Use the function jsonb_populate_record()
in the trigger function, e.g.
create or replace function json_input_trigger()
returns trigger language plpgsql as $$
begin
insert into main_table
select *
from jsonb_populate_record(null::main_table, new.data);
return new;
end $$;

klin
- 112,967
- 15
- 204
- 232
-
I really appreciate your example. Thank you. Can I improve my question in some way? – Bence László Aug 07 '18 at 12:57
-
I think your question is clear enough. But you can edit it if you want to add new aspects. – klin Aug 07 '18 at 13:03
-
The example provided is perfect for experimentation. Thanks! – vhs May 06 '22 at 12:44