DBT Validation for Date with (yyyy-mm-dd) format

858 views Asked by At

I would like to ask for your assistance because I'm currently having difficulties to implement date validation with this format (yyyy-mm-dd) I tried to use this command below, unfortunately I'm getting an error. Your response is highly appreciated. Thank you so much.

      - dbt_expectations.expect_column_values_to_match_regex:
          regex: "^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$"
1

There are 1 answers

0
tconbeer On BEST ANSWER

Your regex is in the style of a raw string (you aren't doubling your backslashes). You need to add an argument to the test definition to tell dbt_expectations to parse it as a raw string:

      - dbt_expectations.expect_column_values_to_match_regex:
          regex: "^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$"
          is_raw: True

Alternatively, you could double all the backslashes:

      - dbt_expectations.expect_column_values_to_match_regex:
          regex: "^\\d{4}\\-(0[1-9]|1[012])\\-(0[1-9]|[12][0-9]|3[01])$"

Docs are here.