create table "database_postgres".database_production."transactions__dbt_tmp" as ( with __dbt__cte__transactions_ab1 as ( -- SQL model to parse JSON blob stored in a single column and extract into separated field columns as described by the JSON Schema select jsonb_extract_path_text(_airbyte_data, '_id') as _id, jsonb_extract_path_text(_airbyte_data, 'total_aibyte_transform') as total_aibyte_transform, jsonb_extract_path_text(_airbyte_data, 'discount_aibyte_transform') as discount_aibyte_transform, _airbyte_ab_id, _airbyte_emitted_at, now() as _airbyte_normalized_at from "database_postgres".database_production._airbyte_raw_transactions as table_alias -- transactions where 1 = 1 ), __dbt__cte__transactions_ab2 as ( -- SQL model to cast each column to its adequate SQL type converted from the JSON schema type select cast(_id as varchar ) as _id,, cast(total_aibyte_transform as varchar ) as total_aibyte_transform, cast(discount_aibyte_transform as varchar ) as discount_aibyte_transform, _airbyte_ab_id, _airbyte_emitted_at, now() as _airbyte_normalized_at from __dbt__cte__transactions_ab1 -- transactions where 1 = 1 ), __dbt__cte__transactions_ab3 as ( -- SQL model to build a hash column based on the values of this record select md5(cast(coalesce(cast(_id as varchar ), '') || '-' || coalesce(cast(total_aibyte_transform as varchar ), '') || '-' || coalesce(cast(discount_aibyte_transform as varchar ), '') as varchar )) as _airbyte_transactions_hashid, tmp.* from __dbt__cte__transactions_ab2 tmp -- transactions where 1 = 1 )-- Final base SQL model select _id, total_aibyte_transform, discount_aibyte_transform, _airbyte_ab_id, _airbyte_emitted_at, now() as _airbyte_normalized_at, _airbyte_transactions_hashid from __dbt__cte__transactions_ab3 -- transactions from "database_postgres".database_production._airbyte_raw_transactions where 1 = 1