insert into metadata_statistics (order_sequence, metadata_defn, total_entries, rundate, metadata_id)
select rownumber() over(order by data_size desc), 
'DataSizePerCategory', data_size, current timestamp, id 
from (
select cab_category_id as id, 
sum(length(coalesce(cab_value_numeric,1))+
length(coalesce(cab_value_string,'N'))+
coalesce(length(cab_value_date),1)) as data_size
from cab 
where  cab_company_id = 40001
and cab_next_version_id = 999999999
group by cab_category_id
) as temp
;
commit;
