Tarantool Sql 更新加入支持
Tarantool Sql Update Join Support
tarantool 是否支持更新连接?我正在检查 tarantool sql 参考资料,但找不到任何样本。
当我尝试使用类似于下面的查询时,出现错误。
UPDATE
COMMISSIONS
SET
COMMISSIONS.COMMISSION =
COMMISSIONS.BASE_AMOUNT * TARGETS.PERCENTAGE
FROM
COMMISSIONS
INNER JOIN TARGETS
ON COMMISSIONS.TARGET_ID = TARGETS.TARGET_ID;
这是架构定义:
CREATE TABLE COMMISSIONS
(
STAFF_ID INTEGER PRIMARY KEY,
TARGET_ID INTEGER,
BASE_AMOUNT INTEGER,
COMMISSION INTEGER
);
CREATE TABLE TARGETS
(
TARGET_ID INTEGER PRIMARY KEY,
PERCENTAGE INTEGER
);
INSERT INTO
TARGETS(TARGET_ID, PERCENTAGE)
VALUES
(1,20),
(2,30),
(3,50),
(4,60),
(5,80);
INSERT INTO
COMMISSIONS(STAFF_ID, BASE_AMOUNT, TARGET_ID)
VALUES
(1,100000,2),
(2,120000,1),
(3,80000,3),
(4,900000,4),
(5,950000,5);
这是我在 运行 更新命令时得到的错误:
Caused by: org.tarantool.TarantoolException: Syntax error at line 1 near '.'
at org.tarantool.TarantoolBase.serverError(TarantoolBase.java:31)
at org.tarantool.TarantoolClientImpl.complete(TarantoolClientImpl.java:571)
at org.tarantool.TarantoolClientImpl.readThread(TarantoolClientImpl.java:491)
at org.tarantool.TarantoolClientImpl.lambda$startThreads(TarantoolClientImpl.java:238)
at java.base/java.lang.Thread.run(Unknown Source)
PS:我正在使用 dbeaver + tarantool jdbc 驱动程序来 运行 查询是否有任何区别。
您可以使用子查询,如下所示:
UPDATE COMMISSIONS SET COMMISSION =
(
SELECT COMMISSIONS.BASE_AMOUNT * TARGETS.PERCENTAGE
FROM TARGETS
WHERE COMMISSIONS.TARGET_ID = TARGETS.TARGET_ID
);
我们的SQL方言来源于SQLite,所以你也可以查看这个相关答案:Update with Join in SQLite
tarantool 是否支持更新连接?我正在检查 tarantool sql 参考资料,但找不到任何样本。 当我尝试使用类似于下面的查询时,出现错误。
UPDATE
COMMISSIONS
SET
COMMISSIONS.COMMISSION =
COMMISSIONS.BASE_AMOUNT * TARGETS.PERCENTAGE
FROM
COMMISSIONS
INNER JOIN TARGETS
ON COMMISSIONS.TARGET_ID = TARGETS.TARGET_ID;
这是架构定义:
CREATE TABLE COMMISSIONS
(
STAFF_ID INTEGER PRIMARY KEY,
TARGET_ID INTEGER,
BASE_AMOUNT INTEGER,
COMMISSION INTEGER
);
CREATE TABLE TARGETS
(
TARGET_ID INTEGER PRIMARY KEY,
PERCENTAGE INTEGER
);
INSERT INTO
TARGETS(TARGET_ID, PERCENTAGE)
VALUES
(1,20),
(2,30),
(3,50),
(4,60),
(5,80);
INSERT INTO
COMMISSIONS(STAFF_ID, BASE_AMOUNT, TARGET_ID)
VALUES
(1,100000,2),
(2,120000,1),
(3,80000,3),
(4,900000,4),
(5,950000,5);
这是我在 运行 更新命令时得到的错误:
Caused by: org.tarantool.TarantoolException: Syntax error at line 1 near '.'
at org.tarantool.TarantoolBase.serverError(TarantoolBase.java:31)
at org.tarantool.TarantoolClientImpl.complete(TarantoolClientImpl.java:571)
at org.tarantool.TarantoolClientImpl.readThread(TarantoolClientImpl.java:491)
at org.tarantool.TarantoolClientImpl.lambda$startThreads(TarantoolClientImpl.java:238)
at java.base/java.lang.Thread.run(Unknown Source)
PS:我正在使用 dbeaver + tarantool jdbc 驱动程序来 运行 查询是否有任何区别。
您可以使用子查询,如下所示:
UPDATE COMMISSIONS SET COMMISSION =
(
SELECT COMMISSIONS.BASE_AMOUNT * TARGETS.PERCENTAGE
FROM TARGETS
WHERE COMMISSIONS.TARGET_ID = TARGETS.TARGET_ID
);
我们的SQL方言来源于SQLite,所以你也可以查看这个相关答案:Update with Join in SQLite