Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
Showing results for 
Search instead for 
Did you mean: 

How to update the items in array of struct column with sql

New Contributor III
create table test.json_test_01 (
	id int,
	description string,
	struct_address STRUCT<street_number: STRING, street_name: STRING, city: STRING, province: STRING>,
	arrary_phone ARRAY<STRUCT<phone_number: STRING, phone_type: STRING>>
insert into test.json_test_01
select 1 as id,
       'first' as description,
       STRUCT('1001', 'street1', 'city1', 'province1') as struct_address,
       ARRAY(STRUCT('1000001', 'Home'), STRUCT('1000002', 'Cell'));
insert into test.json_test_01
select 2 as id,
       'second' as description,
       STRUCT('2001', 'street2', 'city2', 'province2') as struct_address,
       ARRAY(STRUCT('2000001', 'Home'), STRUCT('2000002', 'Work'));

we can update the property in struct column:

update test.json_test_01
set struct_address.street_number = '3001'
where id = 1;

but how to update the property in array of struct?

update test.json_test_01
set arrary_phone[*].phone_type = 'X'
where id = 2;


Not applicable

Hi @Richard Guo​ 

Great to meet you, and thanks for your question!

Let's see if your peers in the community have an answer to your question. Thanks.

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!