             ORDER BY
                 ordinal_position ASC
         LOOP
-            IF (_col != '') THEN
+            IF (jsonb_extract_path_text(_new, _attr) IS NULL AND (TG_OP = 'INSERT' OR jsonb_extract_path_text(_old, _attr) IS NULL)) THEN
+                CONTINUE;
+            ELSIF (_col != '') THEN
                 _col := _col || ', ';
                 _val := _val || ', ';
                 _set := _set || ', ';
             END IF;
 
             _col := _col || format('%I', _attr);
-            _val := _val || format('%L', jsonb_extract_path_text(_data, _attr));
-            _set := _set || format('%I = %L', _attr, jsonb_extract_path_text(_data, _attr));
+            _val := _val || format('%L', jsonb_extract_path_text(_new, _attr));
+            _set := _set || format('%I = %L', _attr, jsonb_extract_path_text(_new, _attr));
         END LOOP;
 
         IF (TG_OP = 'UPDATE') THEN

            ORDER BY
                ordinal_position ASC
        LOOP
            IF (_col != '') THEN
                _col := _col || ', ';
                _val := _val || ', ';
                _set := _set || ', ';
            END IF;

            _col := _col || format('%I', _attr);
            _val := _val || format('%L', jsonb_extract_path_text(_data, _attr));
            _set := _set || format('%I = %L', _attr, jsonb_extract_path_text(_data, _attr));
        END LOOP;

        IF (_col != '' AND _val != '' AND _set != '') THEN

        _attr text;
        _base text;
        _col text := '';
        _ext text;
        _new jsonb;
        _old jsonb;
        _set text := '';
        _sql text := '';
        _val text := '';
