OrientDB - 使用 SUBSELECT 更新
OrientDB - Update with SUBSELECT
我想根据 table 的其他行更新我的 table 的一些行:
我试试这个:
UPDATE MyTable set myField =
(SELECT T1.myField
FROM MyTable T1
WHERE T1.id.substring(start,stop) = MyTable.id.substring(start,stop))
但是 OrientDB 会抛出这样的错误:
com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error on parsing command at position #XXX: Invalid keyword 'T1' Command:
这不是字符串更新,而是整数更新。使用提供的 GratefulDeadDatabase,您可以:
CONNECT remote:localhost/GratefulDeadConcerts;
SELECT performances FROM v;
----+------+------------
# |@CLASS|performances
----+------+------------
0 |null |null
1 |null |5
2 |null |1
3 |null |531
4 |null |394
----+------+------------
UPDATE v SET performances = eval('performances + 2') WHERE performances IS NOT NULL;
SELECT performances FROM v;
----+------+------------
# |@CLASS|performances
----+------+------------
0 |null |null
1 |null |7
2 |null |3
3 |null |533
4 |null |396
----+------+------------
因此更新适用于现有数据。我对 OrientDB 还很陌生,所以如果我只是做了一些非常可怕的错误,也许专家可以告诉我。
更新
请注意,在您的示例中,您正在使用来自相同 table 的值更新 table。也就是说,从 MyTable 到 MyTable(除非我误解了您的查询),甚至在同一行内。您可以在 WHERE 子句上使用条件来仅更新感兴趣的行。在我的示例中,那是
WHERE performances IS NOT NULL
首先,在 OrientDB 中,您不能在 类 上使用 Alias。
在这种情况下,您可以在子查询中使用 $parent.$current,例如:
> update MyTable set myField = (
> select myField
> from MyTable
> where myField is null
> and id.substring(8,13) = $parent.$current.id.substring(8,13) and something else...
> ) where myField is null and something else...
注意id的长度...
最好的问候
M.
我想根据 table 的其他行更新我的 table 的一些行:
我试试这个:
UPDATE MyTable set myField =
(SELECT T1.myField
FROM MyTable T1
WHERE T1.id.substring(start,stop) = MyTable.id.substring(start,stop))
但是 OrientDB 会抛出这样的错误:
com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error on parsing command at position #XXX: Invalid keyword 'T1' Command:
这不是字符串更新,而是整数更新。使用提供的 GratefulDeadDatabase,您可以:
CONNECT remote:localhost/GratefulDeadConcerts;
SELECT performances FROM v;
----+------+------------
# |@CLASS|performances
----+------+------------
0 |null |null
1 |null |5
2 |null |1
3 |null |531
4 |null |394
----+------+------------
UPDATE v SET performances = eval('performances + 2') WHERE performances IS NOT NULL;
SELECT performances FROM v;
----+------+------------
# |@CLASS|performances
----+------+------------
0 |null |null
1 |null |7
2 |null |3
3 |null |533
4 |null |396
----+------+------------
因此更新适用于现有数据。我对 OrientDB 还很陌生,所以如果我只是做了一些非常可怕的错误,也许专家可以告诉我。
更新
请注意,在您的示例中,您正在使用来自相同 table 的值更新 table。也就是说,从 MyTable 到 MyTable(除非我误解了您的查询),甚至在同一行内。您可以在 WHERE 子句上使用条件来仅更新感兴趣的行。在我的示例中,那是
WHERE performances IS NOT NULL
首先,在 OrientDB 中,您不能在 类 上使用 Alias。
在这种情况下,您可以在子查询中使用 $parent.$current,例如:
> update MyTable set myField = (
> select myField
> from MyTable
> where myField is null
> and id.substring(8,13) = $parent.$current.id.substring(8,13) and something else...
> ) where myField is null and something else...
注意id的长度...
最好的问候 M.