
INSERT INTO "itgr"."etl_config_tables" (
	"id", 
	"tenant_id", 
	"command_select", 
	"order_by", 
	"output_table_name", 
	"prefix_view_name", 
	"prefix_table_name", 
	"is_for_sync"
) VALUES (
	'10', --id 
	'11', --tenant_id
	'
	SELECT
		md5(r::text) AS hash_row,
		null::int AS tracking_change_id,
		r.*
	FROM ( 
		SELECT
		   	p.id,
		    p.tenant_id,
		    p.is_active,
		    p.is_deleted,
		    p.app_id,
		    p.record_type_id,
		    p.type as type,
		    p.value as value
		FROM 
			%1$s.public__parameter p
		WHERE 
			 p.is_active = true 
			 AND p.is_deleted = false
	) r
	', -- command_select
	'10', -- order_by
	'sfa_parameter', -- output_table_name
	'', -- prefix_view_name
	'', --prefix_table_name
	true
) --is_for_sync
ON CONFLICT (tenant_id, id) 
DO UPDATE
SET 
	command_select = EXCLUDED.command_select,
	order_by = EXCLUDED.order_by,
	output_table_name = EXCLUDED.output_table_name,
	prefix_view_name = EXCLUDED.prefix_view_name,
	prefix_table_name = EXCLUDED.prefix_table_name,
	is_for_sync = EXCLUDED.is_for_sync
;

-- SELECT itgr.fn_exec_etls(11, 'sfa_parameter');