I'm facing an issue when inserting records into struct field in Azure Databricks using SQL.
In my INSERT INTO statement I have a condition based on which I want to insert either null or a struct.
INSERT INTO my_table (target_column_name)
SELECT
CASE
WHEN condition = true THEN NAMED_STRUCT(<some_fields>)
ELSE NULL
END AS target_column_name
FROM source_table
When I run SELECT only, I'm getting struct when condition is met and null when not met.
However, when I run it as INSERT INTO and check the target table, I'm getting a struct with all fields set to null instead of a single null value.
When I run two separate INSERT statements (one for met condition and second for not met), I'm getting single null value.
I want to avoid having two separate insert statements, how can I force the null value?



ELSE CAST(NULL AS STRUCT<field1: TYPE1, field2: TYPE2>)This should insert a true NULL instead of a null-filled struct