1

So I learnt from here how to insert values into an array column:

INSERT INTO table 
SELECT ARRAY("line1", "line2", "line3") as myArray
FROM source1;

And from here how to insert values into an struct column:

INSERT INTO table 
SELECT NAMED_STRUCT('houseno','123','streetname','GoldStreet', 'town','London', 'postcode','W1a9JF') AS address 
FROM source2;

Now I was trying to insert in the same way values in an array of structs. Which has got the following schema:

additionalattribute:array<struct<attribute_value:string,key:string,value:string>

I tried to extrapolate like this:

  INSERT INTO table 
  ARRAY(NAMED_STRUCT('attribute_value','null','key','null','value','null')) as additionalattribute
  FROM source2;

But it is not working. Does anyone know how to approach this issue?

Ignacio Alorre
  • 7,307
  • 8
  • 57
  • 94

1 Answers1

0

you are missing the select statement after the table name. Demo

create table temp4
(
additionalattribute array<struct<attribute_value:string,key:string,value:string>>
);

INSERT INTO temp4 select 
ARRAY(NAMED_STRUCT('attribute_value','null','key','null','value','null')) as additionalattribute
FROM (select '1' ) t;
hlagos
  • 7,690
  • 3
  • 23
  • 41
  • Thanks for poiting it out, but that is not the issue. I just didn't write the query completly here in stackoverflow and skipped accidentally the select – Ignacio Alorre Jun 05 '18 at 11:16
  • @IgnacioAlorre, I can run the query without problems. what is the issue? please add the error, Hive version and expected results if you can – hlagos Jun 05 '18 at 13:05