I have a column of data that pulls in UTM tag from Google Ads with the below ID's. It contains campaign ID's (The initial part before the "___") and then the ad group ID after. For some cases we only have campaign ID's which are strings, this is the reason why I am type casting with ::TEXT.
This is what the UTM tags look like when pulled in.
835783587___42385125483
eu
968720083___47551372269
en_usa_search_brand
648594695___38174608372
886097479___45386492795
en_trust_control
competitors
es
en_esp_search_route
1072851000___55370810634
I'm trying to split out the ID's from each other and remove the underscores then push these to another table.
umc.campaign is the column that contains the UTM tag.
I'm creating this temp table to then push to the final table below.
CREATE TABLE reports.tmp_sem_attribution AS (
SELECT DISTINCT ON (umc.user_id)
umc.user_id,
umc.source,
umc.campaign ::TEXT,
(SPLIT_PART(REPLACE(campaign,'__','_'),'__',1)) :: TEXT AS campaign_id,
(SPLIT_PART(REPLACE(campaign,'__','_'),'__',2)) :: TEXT AS adgroup_id,
When I use the below query to check the results, I can see that some of the Ad Group ID's are empty or have a space in them.
reports.sem_attribution_v2 is the table where I am pushing out the ID's into two different columns.
SELECT * FROM reports.sem_attribution_v2 WHERE adgroup_id =''
**RESULT**
Campaign_ID AdGroup ID
eu
1560591282
en_usa_search_brand
1560608121
en_trust_control
1560591282
en_fra_search_generic_manual
990427417
eu
If you guys could shed some light on how I could approach this differently or if this query is incorrect. That would be much appreciated.
Thanks.