Type Method
union(_:)
Create a
SQLSubquery expression using an inline query builder which generates the first SELECT query in a UNION.static func union(_ initialBuild: (any SQLSubqueryClauseBuilder) throws -> any SQLSubqueryClauseBuilder) rethrows -> SQLUnionSubqueryBuilder
Discussion
Example usage:
try await db.update("foos")
.set(SQLIdentifier("bar_id"), to: SQLSubquery
.union { $0
.column("id")
.from("bars")
.where("baz", .notEqual, "bamf")
}
.union(all: { $0
.column("id")
.from("bars")
.where("baz", .equal, "bop")
})
.finish()
)
.run()
Note
The need to start with .union and call .finish(), rather than using select(_:) and chaining .union() within that builder, is the result of yet another of the design flaws making use of unions in subqueries far more involved than ought to be necessary.