(如果NOT EXISTS)在CREATE TABLE语句中不起作用

时间:2018-11-26 06:14:54

标签: sql ignite

在测试Ignite 2.6.0(2018-07-16)时,发现(IF NOT EXISTS)语句中的CREATE TABLE不起作用。代码显示如下:

    Class.forName("org.apache.ignite.IgniteJdbcThinDriver");
    try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/"))
    {
        try (Statement stmt = conn.createStatement())
        {
            stmt.executeUpdate("CREATE TABLE IF NOT EXISTS City(id LONG PRIMARY KEY,"
                    + " name VARCHAR) WITH \"template=replicated\"");
        }
    }

第一次运行成功后,再次发生异常:

  

无法执行SQL查询[reqId = 0,req = JdbcQueryExecuteRequest   [schemaName = PUBLIC,pageSize = 1024,maxRows = 0,sqlQry =创建表IF   不存在城市(id长主键,名称为VARCHAR)   “ template = replicated”,args = [],stmtType = UPDATE_STMT_TYPE]]类   org.apache.ignite.internal.processors.query.IgniteSQLException:表   已经存在:CITY,位于   org.apache.ignite.internal.processors.query.h2.ddl.DdlStatementsProcessor.convert(DdlStatementsProcessor.java:582)     在   org.apache.ignite.internal.processors.query.h2.ddl.DdlStatementsProcessor.runDdlStatement(DdlStatementsProcessor.java:511)     在   org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.doRunPrepared(IgniteH2Indexing.java:1736)     在   org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.querySqlFields(IgniteH2Indexing.java:1671)     在   org.apache.ignite.internal.processors.query.GridQueryProcessor $ 4.applyx(GridQueryProcessor.java:2035)     在   org.apache.ignite.internal.processors.query.GridQueryProcessor $ 4.applyx(GridQueryProcessor.java:2030)     在   org.apache.ignite.internal.util.lang.IgniteOutClosureX.apply(IgniteOutClosureX.java:36)     在   org.apache.ignite.internal.processors.query.GridQueryProcessor.executeQuery(GridQueryProcessor.java:2578)     在   org.apache.ignite.internal.processors.query.GridQueryProcessor.querySqlFields(GridQueryProcessor.java:2044)     在   org.apache.ignite.internal.processors.odbc.jdbc.JdbcRequestHandler.executeQuery(JdbcRequestHandler.java:456)     在   org.apache.ignite.internal.processors.odbc.jdbc.JdbcRequestHandler.handle(JdbcRequestHandler.java:203)     在   org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.onMessage(ClientListenerNioListener.java:160)     在   org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.onMessage(ClientListenerNioListener.java:44)     在   org.apache.ignite.internal.util.nio.GridNioFilterChain $ TailFilter.onMessageReceived(GridNioFilterChain.java:279)     在   org.apache.ignite.internal.util.nio.GridNioFilterAdapter.proceedMessageReceived(GridNioFilterAdapter.java:109)     在   org.apache.ignite.internal.util.nio.GridNioAsyncNotifyFilter $ 3.body(GridNioAsyncNotifyFilter.java:97)     在   org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:110)     在   org.apache.ignite.internal.util.worker.GridWorkerPool $ 1.run(GridWorkerPool.java:70)     在java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)     在java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)     在java.lang.Thread.run(未知来源)

2 个答案:

答案 0 :(得分:0)

检查相同,是的,这是一个问题。我为此创建了一个Jira问题:https://issues.apache.org/jira/browse/IGNITE-10414

答案 1 :(得分:0)

我今天遇到了这个问题,并通过修改的sql解决了它

"CREATE TABLE IF NOT EXISTS Timer" 

"CREATE TABLE IF NOT EXISTS myCache.Timer"