Skip to content

Commit

Permalink
fix: handle empty strings, bull values, and incorrect dates for date_…
Browse files Browse the repository at this point in the history
…of_birth column
  • Loading branch information
njogz committed Sep 12, 2024
1 parent 4ccdfc7 commit 4515d7d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion models/contacts/person.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
SELECT
contact.uuid,
contact.saved_timestamp,
(couchdb.doc->>'date_of_birth')::date as date_of_birth,
CASE
WHEN couchdb.doc->>'date_of_birth' IS NULL OR couchdb.doc->>'date_of_birth' = '' THEN NULL
WHEN trim(couchdb.doc->>'date_of_birth') = '' THEN NULL
WHEN (couchdb.doc->>'date_of_birth') ~ '^\d{4}-\d{2}-\d{2}$' THEN (couchdb.doc->>'date_of_birth')::date
ELSE NULL
END as date_of_birth,
couchdb.doc->>'sex' as sex
FROM {{ ref("contact") }} contact
INNER JOIN {{ source('couchdb', env_var('POSTGRES_TABLE')) }} couchdb ON couchdb._id = uuid
Expand Down

0 comments on commit 4515d7d

Please sign in to comment.