向cassandra插入数据的问题
A problem with insert data into cassandra
enter image description here这是table的数据结构。
reviewer_id,reviewer_username,reviewer_personal_details,reviewer_preferences
1,RhMadsen,"{fname: 'Rhea', lanme: 'Madsen', age: 23}","{genre: {id: 14, name: 'Fantasy'}, production_company: {'name': 'Universal Pictures', 'id': 33}, production_country: {'iso_3166_1': 'US', 'name': 'United States of America'}}"
我的插入命令是这样的
INSERT INTO reviewers(
"reviewer_id",
"reviewer_username",
"reviewer_personal_details",
"reviewer_preferences"
)
VALUES (
'30',
'Reilio',
{fname:'Jack',lname:'O'Reilly',age:'19'},
{"genres":{"id":'28',"name":'Action'},"production_company":{"id":'3333',"name":'Kangaroo Pictures'},"production_country":{"iso_3166_1":'AU',"name":'Australia'}}
);
和 shell 总是说它应该以 ; 结尾,但我有一个 ;。总是加注新行。不知道发生了什么。
您的陈述中存在多个问题:
- 你在这个字符串中有单引号字符:
lname:'O'Reilly'
- 这导致它认为该行正在继续。您需要使用附加 '
字符 lname:'O''Reilly'
或使用 $$
作为字符串边界来转义它 correctly。
- 您在地图中对字符串使用了不正确的引号 - 您使用的是双引号而不是单引号
- 某些字段的数据类型不正确,例如
reviewer_id
等
- 您不需要将列名放在双引号中 - 只有当您想要 case-sensitive 名称时才需要这样做
工作查询如下:
INSERT INTO reviewers(
reviewer_id,
reviewer_username,
reviewer_personal_details,
reviewer_preferences
)
VALUES (
30,
'Reilio',
{fname:'Jack',lname:$$O'Reilly$$, age:19},
{'genres':{'id':'28','name':'Action'},
'production_company':{'id':'3333','name':'Kangaroo Pictures'},
'production_country':{'iso_3166_1':'AU','name':'Australia'}
}
);
我建议阅读 Cassandra documentation or grab the free book about Cassandra 并至少阅读第一部分
enter image description here这是table的数据结构。
reviewer_id,reviewer_username,reviewer_personal_details,reviewer_preferences
1,RhMadsen,"{fname: 'Rhea', lanme: 'Madsen', age: 23}","{genre: {id: 14, name: 'Fantasy'}, production_company: {'name': 'Universal Pictures', 'id': 33}, production_country: {'iso_3166_1': 'US', 'name': 'United States of America'}}"
我的插入命令是这样的
INSERT INTO reviewers(
"reviewer_id",
"reviewer_username",
"reviewer_personal_details",
"reviewer_preferences"
)
VALUES (
'30',
'Reilio',
{fname:'Jack',lname:'O'Reilly',age:'19'},
{"genres":{"id":'28',"name":'Action'},"production_company":{"id":'3333',"name":'Kangaroo Pictures'},"production_country":{"iso_3166_1":'AU',"name":'Australia'}}
);
和 shell 总是说它应该以 ; 结尾,但我有一个 ;。总是加注新行。不知道发生了什么。
您的陈述中存在多个问题:
- 你在这个字符串中有单引号字符:
lname:'O'Reilly'
- 这导致它认为该行正在继续。您需要使用附加'
字符lname:'O''Reilly'
或使用$$
作为字符串边界来转义它 correctly。 - 您在地图中对字符串使用了不正确的引号 - 您使用的是双引号而不是单引号
- 某些字段的数据类型不正确,例如
reviewer_id
等 - 您不需要将列名放在双引号中 - 只有当您想要 case-sensitive 名称时才需要这样做
工作查询如下:
INSERT INTO reviewers(
reviewer_id,
reviewer_username,
reviewer_personal_details,
reviewer_preferences
)
VALUES (
30,
'Reilio',
{fname:'Jack',lname:$$O'Reilly$$, age:19},
{'genres':{'id':'28','name':'Action'},
'production_company':{'id':'3333','name':'Kangaroo Pictures'},
'production_country':{'iso_3166_1':'AU','name':'Australia'}
}
);
我建议阅读 Cassandra documentation or grab the free book about Cassandra 并至少阅读第一部分