触发从 PostgreSQL 中的 JSON 对象创建记录

Trigger to create record from JSON object in PostgreSQL

概念:在另一个 table 中创建新的 JSON 对象后,在 table 中创建新记录的触发器。我还不想做任何修改,只是为了 "convert" JSON objects to records with a trigger.

在触发函数中使用函数jsonb_populate_record(),例如

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.