gpt4 book ai didi

ignite - Apache 点燃 : how to insert into table with IDENTITY key (SQL Server)

转载 作者:行者123 更新时间:2023-12-05 08:41:48 27 4
gpt4 key购买 nike

我在 SQL Server 中有一个表,其中主键是自动生成的(标识列),即

CREATE TABLE TableName 
(
table_id INT NOT NULL IDENTITY (1,1),
some_field VARCHAR(20),

PRIMARY KEY (table_id)
);

因为 table_id 是一个自动生成的列,当我实现 SqlFieldQuery INSERT 子句时,我没有为 table_id< 设置任何参数:

sql = new SqlFieldsQuery("INSERT INTO TableName (some_field) VALUES (?)");
cache.query(sql.setArgs("str");

但是在运行时出现以下错误:

Exception in thread "main" javax.cache.CacheException: class org.apache.ignite.internal.processors.query.IgniteSQLException: Failed to execute DML statement [stmt=INSERT INTO TableName (some_field) VALUES (?), params=["str"]]

at org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:807)
at org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:765)
...
Caused by: class org.apache.ignite.internal.processors.query.IgniteSQLException: Failed to execute DML statement [stmt=INSERT INTO TableName (some_field) VALUES (?), params=["str"]]

at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.queryDistributedSqlFields(IgniteH2Indexing.java:1324)
at org.apache.ignite.internal.processors.query.GridQueryProcessor$5.applyx(GridQueryProcessor.java:1815) at org.apache.ignite.internal.processors.query.GridQueryProcessor$5.applyx(GridQueryProcessor.java:1813) at org.apache.ignite.internal.util.lang.IgniteOutClosureX.apply(IgniteOutClosureX.java:36) at org.apache.ignite.internal.processors.query.GridQueryProcessor.executeQuery(GridQueryProcessor.java:2293) at org.apache.ignite.internal.processors.query.GridQueryProcessor.querySqlFields(GridQueryProcessor.java:1820) at org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:795) ... 5 more Caused by: class org.apache.ignite.IgniteCheckedException: Key is missing from query at org.apache.ignite.internal.processors.query.h2.dml.UpdatePlanBuilder.createSupplier(UpdatePlanBuilder.java:331) at org.apache.ignite.internal.processors.query.h2.dml.UpdatePlanBuilder.planForInsert(UpdatePlanBuilder.java:196) at org.apache.ignite.internal.processors.query.h2.dml.UpdatePlanBuilder.planForStatement(UpdatePlanBuilder.java:82) at org.apache.ignite.internal.processors.query.h2.DmlStatementsProcessor.getPlanForStatement(DmlStatementsProcessor.java:438) at org.apache.ignite.internal.processors.query.h2.DmlStatementsProcessor.updateSqlFields(DmlStatementsProcessor.java:164) at org.apache.ignite.internal.processors.query.h2.DmlStatementsProcessor.updateSqlFieldsDistributed(DmlStatementsProcessor.java:222) at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.queryDistributedSqlFields(IgniteH2Indexing.java:1321) ... 11 more

这就是我计划实现插入的方式,因为从缓存中获取最大 table_id、递增和插入似乎更加乏味。我想我可以从插入中省略 table_id 并让 SQL Server 插入 pk,但它似乎不是这样工作的。

您能告诉我这通常应该如何在 Ignite 中实现吗?我检查了 ignite-examples,不幸的是这些例子太简单了(即只有固定键,比如 1 或 2)。

此外,Ignite如何支持序列的使用?

我使用的是 ignite-core 2.2.0。任何帮助表示赞赏!谢谢。

最佳答案

的确,目前不支持自增字段。
作为一种选择,您可以通过例如 Ignite's ID generator 手动生成 ID .

关于ignite - Apache 点燃 : how to insert into table with IDENTITY key (SQL Server),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47585558/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com