AWS Athena INSERT INTO statement: struct col into a varchar column (source struct column has attributes of different types i.e. varchar, int)

0

I am trying to create an insert into statement which queries a source table, which has a column containing a STRUCT data-type. This table is automatically created via crawler and the column definition is as follows:

source table: column A

{ "extensions": { "actual": { "strength": "int", "type": "string", "validity": "int" }, "url": "string" } } I want to take an element of this struct (extensions.actual) and insert into another table TARGET column B

I have currently defined column B as a string. I don't want to define a struct as the 'actual' child elements may over time be added to.

I have an INSERT INTO statement which extracts extensions.actual and attempts to insert, however this is failing due to 'actual' having INT and VARCHAR datatypes.

cast(extensions.actual as varchar)

error: TYPE_MISMATCH: Insert query has mismatched column types

When i run typeof(extensions.actual) i return

row(actual row(strength integer, type varchar, validity integer))

Is there any solution i can implement to insert extensions.actual into target column B without explicitly having to define a structure for column B. Ideally would be a string.

질문됨 일 년 전509회 조회
1개 답변
1
수락된 답변

format('%s',cast(extensions.actual as json)) as extensions_actual

Which effectively converts the struct object to a string.

답변함 일 년 전
profile picture
전문가
검토됨 2달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠