Instance Method
with(isRecursive:name:columns:as:)
@discardableResult func with(isRecursive: Bool, name: some SQLExpression, columns: [any SQLExpression] = [], as query: some SQLExpression) -> Self
Parameters
isRecursiveSpecifies whether or not the CTE is recursive.
nameThe name to assign to the query’s results.
columnsAn optional list of unqualified column names to use for referencing the query’s results. If no column names are provided, the names are inferred from the query. If column names are provided, the number of names provided must match the number of columns returned by the query.
queryAn expression which provides the contents of the CTE. If the CTE is recursive, this must be an expression representing at least one
SELECTstatement which does not refer to the CTE and at least oneUNION ALLorUNION DISTINCTclause terminating with aSELECTstatement which explicitly refers to the CTE itself.
Discussion
This is the common “funnel” method invoked by all other methods provided by SQLCommonTableExpressionBuilder. Most users will not need to call this method directly.
See with(_:columns:as:) and with(recursive:columns:as:) for usage examples.
Warning
As with SQLCommonTableExpression, SQLCommonTableExpressionBuilder does NOT validate that a recursive CTE’s query takes the proper form, nor that a non-recursive CTE’s query is not self-referential. It is the responsibility of the user to specify the flag accurately. Failure to do so will result in generating invalid SQL.