- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
Your screenshot already uses TO_VARIANT_OBJECT; the VOID field inside the STRUCT is what causes the failure.
TO_VARIANT_OBJECT requires every field to be convertible to VARIANT, but VOID is not accepted in that nested path. Scalar CAST(PAYMENT_DATE AS VARIANT) works because untyped NULL can be cast directly to VARIANT.
-
If the intended type is known, cast it at the source, for example
CAST(NULL AS DATE), then useNAMED_STRUCTto preserve the field name. -
If the type is unknown, use
TO_VARIANT_OBJECT(STRUCT(CAST(PAYMENT_DATE AS VARIANT) AS PAYMENT_DATE, TRANSACTION_DATE)). -
For unknown or wide schemas,
PARSE_JSON(TO_JSON(STRUCT(*), map('ignoreNullFields', 'false')))handles VOID fields, but converts DATE and TIMESTAMP values to strings.