Selecto.Builder.SetOperations (Selecto v0.3.8)

SQL generation for set operations (UNION, INTERSECT, EXCEPT).

This module handles the generation of SQL for combining multiple queries using standard SQL set operations.

Link to this section Summary

Functions

Build SQL for set operations in the query.

Extract all parameters from set operation queries.

Check if the query has set operations that need special SQL handling.

Determine if ORDER BY should be applied to the entire set operation result.

Validate that set operations are properly structured for SQL generation.

Wrap a query with set operations in proper parentheses for complex queries.

Link to this section Functions

Link to this function

build_set_operations(selecto)

Build SQL for set operations in the query.

Returns {iodata, [params]} where iodata contains the set operation SQL and params contains the bound parameters from all participating queries.

Link to this function

extract_set_operation_params(selecto)

Extract all parameters from set operation queries.

This ensures all bound parameters from participating queries are included in the final parameter list.

Link to this function

has_set_operations?(selecto)

Check if the query has set operations that need special SQL handling.

Link to this function

should_apply_outer_order_by?(selecto)

Determine if ORDER BY should be applied to the entire set operation result.

In SQL, ORDER BY on set operations applies to the final combined result.

Link to this function

validate_set_operations_for_sql(selecto)

Validate that set operations are properly structured for SQL generation.

Returns :ok or {:error, reason}.

Link to this function

wrap_set_operation_query(sql_iodata, has_outer_clauses)

Wrap a query with set operations in proper parentheses for complex queries.

This is used when set operations need to be combined with ORDER BY, LIMIT, etc.