Selecto.Builder.CteSql (Selecto v0.3.8)

SQL generation for PostgreSQL Common Table Expressions (CTEs).

Generates SQL for both non-recursive and recursive WITH clauses, handling dependency ordering, column specifications, and proper PostgreSQL CTE syntax.

Link to this section Summary

Functions

Build a single CTE definition SQL.

Build WITH clause SQL from a list of CTE specifications.

Create a CTE reference that can be used in joins and queries.

Integrate CTEs with a main query, combining the WITH clause with the query.

Link to this section Functions

Link to this function

build_cte_definition(spec)

Build a single CTE definition SQL.

Returns {cte_definition_iodata, parameters} for a single CTE.

Link to this function

build_with_clause(ctes)

Build WITH clause SQL from a list of CTE specifications.

Returns {with_clause_iodata, parameters} tuple with properly ordered CTEs and parameter bindings.

Link to this function

create_cte_reference(cte_name)

Create a CTE reference that can be used in joins and queries.

Returns a structure that represents the CTE as a queryable table.

Link to this function

integrate_ctes_with_query(ctes, query_iodata, query_params)

Integrate CTEs with a main query, combining the WITH clause with the query.

Returns the complete SQL with CTEs at the top.