1

我使用以下语法创建了一个表:

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;"

谁能告诉我为什么在尝试更新对象字段数组时出现此错误。

4

1 回答 1

4

我们的 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
于 2014-05-14T14:36:44.080 回答