OtterMind/Chat2DB · error · CliDomainException
sql_query_failed
sql_query_failed
Error message
sql_query_failed
What it means
CliDomainException code sql_query_failed from CliSqlServiceImpl execute: after dlTemplateService.execute runs the SQL, the selected ExecuteResponse has success != Boolean.TRUE. The message defaults to the response message (or 'SQL query failed.') and details come from executeResultDetails. Indicates the SQL reached the DB but the engine rejected it or the execution errored.
Source
Thrown at chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/cli/CliSqlServiceImpl.java:49
@Override
public CliSqlQueryResponse query(CliSqlQueryRequest request) {
DbDlExecuteRequest param = new DbDlExecuteRequest();
param.setDataSourceId(request.getDataSourceId());
param.setDatabaseName(request.getDatabaseName());
param.setSchemaName(request.getSchemaName());
param.setSql(request.getSql());
param.setPageNo(request.safePageNo());
param.setPageSize(request.safePageSize());
param.setResultSetId(request.getResultSetId());
param.setSingle(true);
List<ExecuteResponse> result = dlTemplateService.execute(param);
ExecuteResponse executeResult = selectResult(result, request.getResultSetId());
if (executeResult == null) {
return cliSqlConverter.emptyQueryResponse(request);
}
if (!Boolean.TRUE.equals(executeResult.getSuccess())) {
throw new CliDomainException("sql_query_failed",
defaultErrorMessage(executeResult.getMessage(), "SQL query failed."),
executeResultDetails(executeResult));
}
return cliSqlConverter.executeResult2response(executeResult, request);
}
private ExecuteResponse selectResult(List<ExecuteResponse> results, Integer resultSetId) {
if (results == null || results.isEmpty()) {
return null;
}
if (resultSetId != null) {
return results.stream()
.filter(Objects::nonNull)
.filter(result -> resultSetId.equals(result.getResultSetId()))
.findFirst()
.orElseThrow(() -> new CliDomainException("sql_result_set_not_found",
"SQL result set not found: " + resultSetId,
Map.of("resultSetId", resultSetId, "availableResultSetIds", availableResultSetIds(results))));View on GitHub (pinned to 5ee1e990e7)
Solutions
- Read the returned message and details to get the engine's native error (syntax, missing object, permission).
- Run the same SQL directly against the DB with the same user/schema to reproduce the engine error.
- Confirm the active dataSourceId/databaseName/schemaName match where the objects exist.
- For privileges, grant the needed permissions; for timeouts, tune the statement or increase limits.
Example fix
// before
sql_execute({ sql: 'SELECT * FROM nonexistent_table', dataSourceId, databaseName })
// after
sql_execute({ sql: 'SELECT * FROM existing_table', dataSourceId, databaseName }) Defensive patterns
Strategy: try-catch
Validate before calling
// validate SQL and context before execute
if (StringUtils.isBlank(request.getSql())) {
throw new IllegalArgumentException("sql is required");
}
if (request.getDataSourceId() == null && StringUtils.isBlank(request.getDatabaseName())) {
throw new IllegalArgumentException("dataSourceId or databaseName required");
} Try / catch
try {
return cliSqlService.execute(request);
} catch (CliDomainException e) {
if ("sql_query_failed".equals(e.getCode())) {
return sqlFailedResponse(e.getMessage(), e.getDetails());
}
throw e;
} Prevention
- Validate object names/SQL against the target schema before executing.
- Confirm the active datasource/database/schema match where objects live.
- Grant only the needed privileges to the executing DB user.
- Test statements in a scratch session before automating them.
When it happens
Trigger: Executing a SQL statement that is syntactically invalid, references a missing table/column, violates a constraint/privilege, times out, or otherwise returns an error from the JDBC layer wrapped into ExecuteResponse.
Common situations: Typo in SQL or object name; wrong database/schema selected; insufficient grants; statement type not permitted in this context; query timeout or connection drop mid-execution.
Related errors
- datasource_connection_failed
- Redis command execution failed, sql=${originalSql}
- Redis update command failed, sql={sql}
- datasource_not_found
- invalid_connection_test_args
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/503b58469e5abb32.
Report an issue: GitHub.