Skip to content

Commit

Permalink
fix: date casting in person model
Browse files Browse the repository at this point in the history
  • Loading branch information
njogz committed Sep 24, 2024
1 parent 3e478cc commit 136dd23
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,
NULLIF(couchdb.doc->>'date_of_birth', '')::date as date_of_birth,
CASE
WHEN NULLIF(couchdb.doc->>'date_of_birth', '') IS NULL THEN NULL
WHEN couchdb.doc->>'date_of_birth' ~ '^\d{4}-\d{2}-\d{2}$' THEN (couchdb.doc->>'date_of_birth')::date
WHEN couchdb.doc->>'date_of_birth' ~ '^\d{2}/\d{2}/\d{4}$' THEN TO_DATE(couchdb.doc->>'date_of_birth', 'DD/MM/YYYY')
ELSE NULL
END as date_of_birth,
couchdb.doc->>'sex' as sex,
couchdb.doc->>'phone' AS phone,
couchdb.doc->>'alternative_phone' AS phone2,
Expand Down

0 comments on commit 136dd23

Please sign in to comment.