4

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.

0

1 Answer 1

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 $$;

Fully working example.

Sign up to request clarification or add additional context in comments.

3 Comments

I really appreciate your example. Thank you. Can I improve my question in some way?
I think your question is clear enough. But you can edit it if you want to add new aspects.
The example provided is perfect for experimentation. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.