Tencent/WeKnora · error

functions in FROM clause are not allowed

Error message

functions in FROM clause are not allowed

What it means

Policy error in validateFromItem: a RangeFunction (set-returning or scalar function used as a FROM item) was encountered and is never permitted, blocking constructs like generate_series or file-reading functions from appearing in FROM.

Source

Thrown at internal/utils/inject.go:1474

		return nil
	}

	// Handle RangeSubselect (subquery in FROM)
	if rss := node.GetRangeSubselect(); rss != nil {
		if v.checkSubqueries {
			return fmt.Errorf("subqueries in FROM clause are not allowed")
		}
		// SECURITY: Even when subqueries are permitted, recurse into the
		// subquery so dangerous constructs hidden inside it are still
		// validated. Without this, a FROM subquery like
		//   (SELECT * FROM read_text('/etc/passwd'))
		// smuggles a RangeFunction past the check below.
		return v.validateSubquery(rss.Subquery, tables, result)
	}

	// Handle RangeFunction (function in FROM)
	if node.GetRangeFunction() != nil {
		return fmt.Errorf("functions in FROM clause are not allowed")
	}

	return nil
}

// validateSubquery validates a SELECT statement nested in a FROM subquery.
// It reuses the FROM-item and expression validators so RangeFunction and
// dangerous function checks apply recursively to arbitrarily nested subqueries.
func (v *sqlValidator) validateSubquery(node *pg_query.Node, tables map[string]string, result *SQLValidationResult) error {
	if node == nil {
		return nil
	}
	sub := node.GetSelectStmt()
	if sub == nil {
		return nil
	}
	for _, fromItem := range sub.FromClause {
		if err := v.validateFromItem(fromItem, tables, result); err != nil {

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Remove the function from FROM and express the logic in allowed columns
  2. Materialize the needed rows into an allowed table beforehand
  3. Use JOINs against permitted tables instead of set-returning functions
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/utils/inject.go:1474 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/d7dada8bb4c9e2b1. Report an issue: GitHub.