Skip to content

Create hubs from staging table where null is possible #222

Answered by tkiehn
mattiasthalen asked this question in Q&A
Discussion options

You must be logged in to vote

It is hashing "" because the CONCAT()-Method implicitly converts the null value to an empty string, resulting in CONCAT('"', '', '"').

If you try out using the double pipe || like so:

COALESCE(LOWER(MD5(NULLIF(CAST(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(CONCAT(
        COALESCE(('"' || REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(TRIM(BOTH ' ' FROM CAST(parent_id AS VARCHAR)), '\\', '\\\\'), '"', '\"'), '^^', '--') || '"'), '^^')
        ), '\n', '') 
        , '\t', '') 
        , '\v', '') 
        , '\r', '') AS VARCHAR), '^^'))), '00000000000000000000000000000000') AS parent_unit_hk

it should return null and therefore the zero key as hashkey.

My code:

select
COALESCE(LO…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@mattiasthalen
Comment options

@tkiehn
Comment options

tkiehn Aug 15, 2024
Collaborator

@mattiasthalen
Comment options

@tkiehn
Comment options

tkiehn Aug 15, 2024
Collaborator

Answer selected by mattiasthalen
@mattiasthalen
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants