{"record":{"id":"d8d90d2123a71994","repo":"prestodb/presto","slug":"inserting-into-an-unpartitioned-table-that-were-ad","errorCode":null,"errorMessage":"Inserting into an unpartitioned table that were added, altered, or inserted into in the same transaction is not supported","messagePattern":"Inserting into an unpartitioned table that were added, altered, or inserted into in the same transaction is not supported","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/SemiTransactionalHiveMetastore.java","lineNumber":579,"sourceCode":"                                    table,\n                                    Optional.empty(),\n                                    Optional.of(currentLocation),\n                                    Optional.of(fileNames),\n                                    false,\n                                    merge(currentStatistics, statisticsUpdate),\n                                    statisticsUpdate,\n                                    emptyList()),\n                            context));\n            return;\n        }\n\n        switch (oldTableAction.getType()) {\n            case DROP:\n                throw new TableNotFoundException(schemaTableName);\n            case ADD:\n            case ALTER:\n            case INSERT_EXISTING:\n                throw new UnsupportedOperationException(\"Inserting into an unpartitioned table that were added, altered, or inserted into in the same transaction is not supported\");\n            default:\n                throw new IllegalStateException(\"Unknown action type\");\n        }\n    }\n\n    public synchronized void truncateUnpartitionedTable(ConnectorSession session, String databaseName, String tableName)\n    {\n        checkReadable();\n        Optional<Table> table = getTable(\n                new MetastoreContext(\n                        session.getIdentity(),\n                        session.getQueryId(),\n                        session.getClientInfo(),\n                        session.getClientTags(),\n                        session.getSource(),\n                        getMetastoreHeaders(session),\n                        isUserDefinedTypeEncodingEnabled(session),\n                        columnConverterProvider,","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/SemiTransactionalHiveMetastore.java#L561-L597","documentation":"finishInsertIntoExistingTable handles inserts into unpartitioned tables. If the table's pending action in this transaction is ADD, ALTER, or INSERT_EXISTING, the buffered-action model cannot combine that with another data insert, so it throws UnsupportedOperationException at finish time.","triggerScenarios":"Two or more INSERT INTO statements targeting the same unpartitioned Hive table within one transaction, or an insert following createTable/alterTable of that table in the same transaction.","commonSituations":"Multi-statement ETL scripts appending to the same target table several times in one session; jobs that create a table then insert into it twice; union-all style loading implemented as sequential inserts.","solutions":["Combine multiple inserts into a single INSERT (e.g. via a UNION query) so only one insert action is recorded","Commit between inserts, using a fresh transaction for each","Create the table and do exactly one insert per transaction; use INSERT_EXISTING only once per transaction"],"exampleFix":"// before\nINSERT INTO t SELECT ...;\nINSERT INTO t SELECT ...; // same transaction\n// after\nINSERT INTO t SELECT ... UNION ALL SELECT ...; // single statement","handlingStrategy":"try-catch","validationCode":"// ensure only one insert action per unpartitioned table per transaction\nif (insertedTablesInTx.contains(tableName) && isUnpartitioned(table)) {\n    throw new IllegalStateException(\"Combine inserts or commit between them\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    metastore.finishInsertIntoExistingTable(ctx, handle, ...);\n} catch (UnsupportedOperationException e) {\n    // restructure: merge inserts into one statement, or commit between inserts\n    throw new IllegalStateException(\"Only one insert per unpartitioned table per transaction\", e);\n}","preventionTips":["One INSERT per unpartitioned table per transaction","Use UNION ALL to combine multiple loads","Commit between sequential appends"],"tags":["hive","transaction","insert","unsupported-operation"],"backgroundTag":"unsupported-operation-in-transaction","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}