概述
插入覆盖子句insert().overwrite().into()
覆盖一个schema中已有的点、边,或插入新的点、边。
语法
// 插入或覆盖点
insert().overwrite().into(@<schema>).nodes([
{<property1>: <value1>, <property2>: <value2>, ...},
{<property1>: <value1>, <property2>: <value2>, ...}
])
// 插入或覆盖边
insert().overwrite().into(@<schema>).edges([
{<property1>: <value1>, <property2>: <value2>, ...},
{<property1>: <value1>, <property2>: <value2>, ...}
])
- 在
into()
方法中指定一个schema。 - 在
nodes()
或edges()
方法中添加一个或多个点或边。- 在
{ }
里填写点、边属性键值对。 - 如果只插入覆盖一个点或一条边,可以省略外层中括号
[ ]
。
- 在
- 支持定义子句别名,数据类型为NODE或EDGE。
当一个点或一条边被覆盖时:
- 使用
_id
和/或_uuid
指定要覆盖的点;使用_uuid
、_from
和_to
(或_from_uuid
和_to_uuid
)指定要覆盖的边。 - 指定的自定义属性值被覆盖;未指定的自定义属性被赋值为
null
。 - 系统属性(
_id
、_uuid
、_from
、_to
、_from_uuid
、_to_uuid
)的值保持不变。
如果指定的_id
或_uuid
在当前图集中不存在,或未指定_id
和_uuid
,则插入新的点。
如果指定的_uuid
在当前图集中不存在,或未指定_uuid
,则插入新的边。
示例图集

在一个空图集中,逐行运行以下UQL语句,创建示例图集:
create().node_schema("user").edge_schema("follow")
create().node_property(@user, "name").node_property(@user, "age", int32).edge_property(@follow, "time", datetime)
insert().into(@user).nodes([{_id:"U001", _uuid:1, name:"Jason", age:30}, {_id:"U002", _uuid:2, name:"Tim"}, {_id:"U003", _uuid:3, name:"Grace", age:25}, {_id:"U004", _uuid:4, name:"Ted", age:26}])
insert().into(@follow).edges([{_uuid:1, _from_uuid:4, _to_uuid:1, time:"2021-9-10"}, {_uuid:2, _from_uuid:3, _to_uuid:2, time:"2020-3-12"}, {_uuid:3, _from_uuid:4, _to_uuid:2, time:"2023-7-30"}])
示例
插入覆盖点
insert().overwrite().into(@user).nodes([
{_id: "U001", name: "John"},
{_id: "U005", name: "Alice"},
{age: 12}
]) as n
return n{*}
- 第一个点指定
_id
为U001,在当前图集中已存在,因此覆盖原数据。 - 第二个点指定
_id
为U005,在当前图集中不存在,因此作为新数据插入。 - 第三个点未指定
_id
和_uuid
,因此作为新数据插入。
结果:
_id |
_uuid | name | age |
---|---|---|---|
U001 | 1 | John | null |
U005 | 5 | Alice | null |
ULTIPA8000000000000006 | 6 | null |
12 |
插入覆盖边
insert().overwrite().into(@follow).edges([
{_uuid: 1, _from: "U004", _to: "U001"},
{_uuid: 4, _from: "U002", _to: "U003"},
{_from: "U002", _to: "U001", time: "2023-9-6"}
]) as e
return e{*}
- 第一条边指定
_uuid
为1、_from
为U004、_to
为U001,在当前图集中已存在,因此覆盖原数据。 - 第二条边指定
_uuid
为4,在当前图集中不存在,因此作为新数据插入。 - 第三条边未指定
_uuid
,因此作为新数据插入。
结果:
_uuid | _from | _to | _from_uuid |
_to_uuid | time |
---|---|---|---|---|---|
1 | U004 | U001 | 4 | 1 | null |
4 | U002 | U003 | 2 | 3 | null |
5 | U002 | U001 | 2 | 1 | 2023-09-06 00:00:00 |
常见失败原因
- 指定的点、边数据与指定的schema不匹配。
- 同时指定点的
_id
和_uuid
时,其中一个值在图集中存在,而另一个值不存在。 - 同时指定点的
_id
和_uuid
时,虽然它们都在图集中存在,但是二者不匹配。 - 未指定边的起点或终点。
- 指定的边起点或终点在图集中不存在。
- 指定边的
_uuid
在图集中存在,但指定的边起点或终点不正确。