I am writing a trigger where I need to convert NEW row into a json and insert into an other table. I am not getting it right.
CREATE OR REPLACE FUNCTION public.eventlogs_add_user()
RETURNS trigger AS
$BODY$
DECLARE newRecord JSON;
BEGIN
newRecord := row_to_json(row)
from (NEW) row;
// Insert newRecord into another table
RETURN NEW;
END$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION public.eventlogs_add_user()
OWNER TO postgres;
-----------------------------------------------------------
changing
newRecord := row_to_json(row)
from (NEW) row;
to
newRecord := row_to_json(NEW.*);
should help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With