DECLARE
immutable_cols TEXT[] := ARRAY['id','sq_id','last_date'];
op_value JSON;
BEGIN
IF TG_OP = 'UPDATE' THEN
SELECT json_agg(json_build_object('Updated', pre.key , 'From', pre.value, 'To', post.value)) INTO op_value
FROM jsonb_each(to_jsonb(OLD)) AS pre CROSS JOIN jsonb_each(to_jsonb(NEW)) AS post
WHERE pre.key = post.key AND pre.value IS DISTINCT FROM post.value;
RAISE NOTICE '% ', op_value;
IF (json_array_length(op_value) > 0 )THEN
INSERT INTO table_name (col_1,col_2)
values (OLD.col_1,op_value);
NEW.col_3 = now();
END IF;
IF(NEW.col_4) THEN
INSERT INTO REQUEST_TRAIL (col_1,col_2)
values (OLD.col_1,json_build_object('From',OLD.col_4,'To',NEW.col_4));
NEW.col_5=now();
END IF;
RETURN NEW;
END IF;
END
$$
LANGUAGE plpgsql VOLATILE;
Я получил ошибку для
ОШИБКА: неверный синтаксис ввода для типа boolean: "{" To ":" Tech "}"
КОНТЕКСТ: PL / pg SQL Функциональная линия 22 при IF SQL состояние: 22P02