create materialized view sav_Test_Storage_Obj_Study_mat_view as
SELECT
	*
FROM
	crosstab(
		'with target_objects as (
			select
				distinct so.storage_object_id,
				so.reference_id as "referenceId",
				so.file_status as "fileStatus",
				so.import_id as "importId"
			from storage_object so 
			where
				lower(so.reference_type) = ''study''
				and so.reference_id in (''Test_Storage_Obj_Study'')
				and so.is_deleted = 0
				and lower(so.file_status) <> ''uploaded''
				and so.file_status <> ''''
				and so.file_status IS NOT NULL
			order by 1
		),
		image_type_filter as (
			select
				sav.storage_object_id
			from storage_attribute_value sav
			join target_objects tobj on
				tobj.storage_object_id = sav.storage_object_id
			where
				sav.is_deleted = 0
				and sav.attribute_name = ''image_type''
				and sav.attribute_value is not null
			--limit 10 offset 0
		)
		select
			sav.storage_object_id as "storageObjectId",
			''image'' as "attributeName",
			tobj."referenceId",
			tobj."fileStatus",
			tobj."importId",
			sav.attribute_name,
			sav.attribute_value
		from
			storage_attribute_value sav
		join image_type_filter itf on
			itf.storage_object_id = sav.storage_object_id
		join target_objects tobj on
			tobj.storage_object_id = sav.storage_object_id;
		',
		'select
			distinct sa.attribute_name
		from study_attribute sa
		inner join study s on
			s.study_id = sa.study_id
		where
			s.study_identifier = ''Test_Storage_Obj_Study''
			and sa.attribute_name not in (
				select da.attribute_value
				from discrete_attribute da
				where
					da.attribute_name = ''STORAGE_SYSTEM_CONFIGURATION''
			)
			and sa.is_deleted = 0
		order by 1
		'
	)
	AS (
		"storageObjectId" numeric,
		"attributeName" text,
		"referenceId" text,
		"fileStatus" text,
		"importId" text,
		"analysis_type" text,
		"arm_s" text,
		"attribute1" text,
		"attribute10" text,
		"attribute11" text,
		"attribute12" text,
		"attribute13" text,
		"attribute14" text,
		"attribute15" text,
		"attribute16" text,
		"attribute17" text,
		"attribute18" text,
		"attribute19" text,
		"attribute2" text,
		"attribute20" text,
		"attribute21" text,
		"attribute22" text,
		"attribute23" text,
		"attribute24" text, 
		"attribute25" text, 
		"attribute26" text, 
		"attribute27" text, 
		"attribute28" text, 
		"attribute29" text, 
		"attribute3" text, 
		"attribute30" text, 
		"attribute31" text, 
		"attribute4" text, 
		"attribute5" text, 
		"attribute6" text, 
		"attribute7" text, 
		"attribute8" text, 
		"attribute9" text, 
		"Buffer Lot Number" text, 
		"Cartridge Expiry Date" text, 
		"Cartridge Lot Number" text, 
		"cohort_group" text, 
		"Comments" text, 
		"Datafile (Hemex only)" text, 
		"Date of first or only dose" text, 
		"Date of sample Collection (YYYY/MM/DD)" text, 
		"Date of second dose (if applicable)" text, 
		"date_Test" text, 
		"Date test was conducted" text, 
		"Days since symptom onset (1-5 days)" text, 
		"DeviceID" text, 
		"disease_detail" text, 
		"FIA Multipack Expiry Date" text, 
		"Gender" text, 
		"Hemex only" text, 
		"image_format" text, 
		"image_name" text, 
		"image_type" text, 
		"image_type_detail" text, 
		"kallisto_bootstrap" text, 
		"modality" text, 
		"Mylab FIA Multipack Lot Number" text, 
		"panel" text, 
		"parent_population" text, 
		"path_fastq_r1" text, 
		"path_fastq_r2" text, 
		"path_index_file" text, 
		"path_wdl" text, 
		"Patient Symptoms (add up to three symptoms per subject)" text, 
		"PCR ct value" text, 
		"PCR Result (Positive/Negative)" text, 
		"phase" text, 
		"phred" text, 
		"population" text, 
		"Reader Test Result (Positive/Negative/Invalid/Test Problem Encountered)" text, 
		"reference_id" text, 
		"reference_type" text, 
		"response" text, 
		"response_duration_in_months" text, 
		"response_group" text, 
		"response_survival_in_months" text, 
		"response_survival_status" text, 
		"Sample collected by (Initials)" text, 
		"screen_detail" text, 
		"series_id" text, 
		"session" text, 
		"site_id" text, 
		"slide_id" text, 
		"spa" text, 
		"Subject Age (years)" text, 
		"subject_id" text, 
		"Subject received COVID-19 vaccine?" text, 
		"Test_21" text, 
		"thumbnailUrl" text, 
		"Time of Gazelle Nasal Swab Sample Collection  (HR:MIN in 24-hr format)" text, 
		"Time of RT-PCR Sample Collection (HR:MIN in 24-hr format)" text, 
		"timepoint" text, 
		"Time test was conducted" text, 
		"trimmomatic_params" text, 
		"User" text, 
		"User running test" text, 
		"Vaccine Name (if Other)" text, 
		"viewerUrl" text, 
		"visit_date" text, 
		"Which vaccine?" text
	)

I want to update this materialized view on insert, update or delete in storage_object and storage_attribute_value tables. The flow goes like this: first the storage_object table gets the object entry and after some processing, storage_attribute_value table gets populated with corresponding object values