Question

I created a table with following syntax:

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
)

And I inserted a record without "poll_rating" field which is actually an array of objects fields.

Now when I try to update a poll_rating with the following commands:

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

I'm getting an error message like this:

"SQLParseException[line 1:31: no viable alternative at input '[']; nested: ParsingException[line 1:31: no viable alternative at input '[']; nested: NoViableAltException;"

Can anyone tell me why I get this error when I try to update the array of objects fields.

Was it helpful?

Solution

Defining arrays and objects directly in SQL statement is currently not supported by our SQL parser, please use parameter substitution using placeholders instead as described here: https://crate.io/docs/current/sql/rest.html

Example using curl is as below:

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top