我使用以下语法创建了一个表:
create table poll(poll_id string primary key,
poll_type_id integer,
poll_rating array(object as (rating_id integer,fk_user_id string, israted_image1 integer, israted_image2 integer, updatedDate timestamp, createdDate timestamp )),
poll_question string,
poll_image1 string,
poll_image2 string
)
我插入了一条没有" poll_rating"字段,实际上是一个对象字段数组。
现在,当我尝试使用以下命令更新poll_rating时:
update poll set poll_rating = [{"rating_id":1,"fk_user_id":-1,"israted_image1":1,"israted_image2":0,"createddate":1400067339.0496}] where poll_id = "f748771d7c2e4616b1865f37b7913707";
我收到如下错误消息:
"SQLParseException[line 1:31: no viable alternative at input '[']; nested: ParsingException[line 1:31: no viable alternative at input '[']; nested: NoViableAltException;"
当我尝试更新对象字段数组时,有人能告诉我为什么会出现此错误。
答案 0 :(得分:3)
我们的SQL解析器目前不支持直接在SQL语句中定义数组和对象,请使用占位符替换参数,如下所述: https://crate.io/docs/current/sql/rest.html
使用curl的示例如下:
curl -sSXPOST '127.0.0.1:4200/_sql?pretty' -d@- <<- EOF
{"stmt": "update poll set poll_rating = ? where poll_id = ?",
"args": [ [{"rating_id":1,"fk_user_id":-1,"israted_image1":1,"israted_image2":0,"createddate":1400067339.0496}], "f748771d7c2e4616b1865f37b7913707" ]
}
EOF