Tencent/WeKnora · error

no valid table found in query

Error message

no valid table found in query

What it means

Guard error in the SQL validator (inject.go): after validating FROM, JOIN, HAVING, and ORDER BY clauses, no recognized table was collected into tablesInQuery, meaning the query references no permitted table. This is a security fail-closed rejection of queries the validator cannot map to allowed tables.

Source

Thrown at internal/utils/inject.go:1410

	}

	// Validate HAVING clause
	if stmt.HavingClause != nil {
		if err := v.validateNode(stmt.HavingClause, result); err != nil {
			return err
		}
	}

	// Validate ORDER BY clause
	for _, sortBy := range stmt.SortClause {
		if err := v.validateNode(sortBy, result); err != nil {
			return err
		}
	}

	// Ensure at least one valid table is referenced
	if len(tablesInQuery) == 0 {
		return fmt.Errorf("no valid table found in query")
	}

	return nil
}

// validateFromItem validates a FROM clause item
func (v *sqlValidator) validateFromItem(node *pg_query.Node, tables map[string]string, result *SQLValidationResult) error {
	if node == nil {
		return nil
	}

	// Handle RangeVar (simple table reference)
	if rv := node.GetRangeVar(); rv != nil {
		tableName := strings.ToLower(rv.Relname)

		// Check for schema qualification
		if v.checkSchemaAccess && rv.Schemaname != "" {
			schemaName := strings.ToLower(rv.Schemaname)

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Reference at least one allowed table in FROM/JOIN
  2. Remove constructs that hide tables from validation (e.g. bare SELECT without FROM)
  3. Check table-name casing; names are lowercased before matching
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/utils/inject.go:1410 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/d0ac9176f12c49d4. Report an issue: GitHub.