在嵌套对象列中添加列

  • 本文关键字:添加 对象 嵌套 crate
  • 更新时间 :
  • 英文 :


我一直试图在另一个对象列中的对象列中添加一列,但无法做到(对于嵌套对象)。

添加列

在对象内部添加列是直接的。如何在嵌套对象中添加一级(或N级)深的列?

create table my_table (name string, age integer, book object as (isbn string));

示例行:{"age": 34, "book": {"isbn": "1"}, "name": "my_name"}

我试图在图书对象列中添加一个对象列"author",但以下alter语句未能通过

alter table my_table add column person['book['author']'] object as (authorId as integer)
alter table my_table add column person['book']['author'] object as (authorId as integer)
alter table my_table add column person['book[author]'] object as (authorId as integer)
alter table my_table add column person[book['author']] object as (authorId as integer)

在嵌套对象中添加列的正确语法是什么?

谨致问候。

嵌套对象以以下形式访问:

select obj['level1']['level2']['level3']

等等。

因此,alter table语句看起来像您的第二个示例,但没有"as integer":

alter table my_table add column book['person']['author'] object as ("authorId" integer);

(注意authorId用双引号来保留大小写,如果没有它,它将变成小写)

或者,同样的事情也可以用稍微不同的语法来完成:

alter table my_table add column book['person']['author']['authorId'] integer;

最新更新