CREATE MATERIALIZED VIEW insights.account_to_account_groups_membership_mv AS
SELECT
account_id,
account_group_id,
effective_start_date,
effective_end_date,
source_entity_type
FROM insights.account_to_account_groups_mv AS account_to_account_groups_mv_next
UNION ALL
SELECT
uam.account_id,
'account_group_' || MD5(CAST((
uam.user_id || uam.type
) AS BYTEA)) AS account_group_id,
CAST('1970-01-01' AS DATE) AS effective_start_date,
CAST(NULL AS DATE) AS effective_end_date,
CAST('user' AS VARCHAR) AS source_entity_type
FROM insights.user_account_membership_mv AS uam