Skip to content
# Class: BinarySelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:34

Represents a binary SELECT expression (UNION/INTERSECT/EXCEPT) composed from two SelectQuery values.

Example ​

typescript
const parts = [
  SelectQueryParser.parse('SELECT id, name FROM users').toSimpleQuery(),
  SelectQueryParser.parse('SELECT id, name FROM archived_users').toSimpleQuery()
];
const unionQuery = QueryBuilder.buildBinaryQuery(parts, 'union');

Related tests: packages/core/tests/models/SelectQueryUnion.test.ts

Extends ​

Implements ​

Constructors ​

Constructor ​

new BinarySelectQuery(left, operator, right): BinarySelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:42

Parameters ​

left ​

SelectQuery

operator ​

string

SelectQuery

Returns ​

BinarySelectQuery

Overrides ​

SqlComponent.constructor

Properties ​

kind ​

static kind: symbol

Defined in: packages/core/src/models/BinarySelectQuery.ts:35

Overrides ​

SqlComponent.kind


__selectQueryType ​

readonly __selectQueryType: "SelectQuery" = 'SelectQuery'

Defined in: packages/core/src/models/BinarySelectQuery.ts:36

Implementation of ​

SelectQuery.__selectQueryType


headerComments ​

headerComments: string[] | null = null

Defined in: packages/core/src/models/BinarySelectQuery.ts:37

Implementation of ​

SelectQuery.headerComments


left ​

left: SelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:38


operator ​

operator: RawString

Defined in: packages/core/src/models/BinarySelectQuery.ts:39


right ​

right: SelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:40


comments ​

comments: string[] | null = null

Defined in: packages/core/src/models/SqlComponent.ts:29

Implementation of ​

SelectQuery.comments

Inherited from ​

SqlComponent.comments


positionedComments ​

positionedComments: PositionedComment[] | null = null

Defined in: packages/core/src/models/SqlComponent.ts:32

Implementation of ​

SelectQuery.positionedComments

Inherited from ​

SqlComponent.positionedComments

Methods ​

union() ​

union(query): BinarySelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:57

Appends another query to this binary query using UNION as the operator. This creates a new BinarySelectQuery where the left side is this binary query and the right side is the provided query.

Parameters ​

query ​

SelectQuery

The query to append with UNION

Returns ​

BinarySelectQuery

A new BinarySelectQuery representing "(this) UNION query"


unionAll() ​

unionAll(query): BinarySelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:69

Appends another query to this binary query using UNION ALL as the operator. This creates a new BinarySelectQuery where the left side is this binary query and the right side is the provided query.

Parameters ​

query ​

SelectQuery

The query to append with UNION ALL

Returns ​

BinarySelectQuery

A new BinarySelectQuery representing "(this) UNION ALL query"


intersect() ​

intersect(query): BinarySelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:81

Appends another query to this binary query using INTERSECT as the operator. This creates a new BinarySelectQuery where the left side is this binary query and the right side is the provided query.

Parameters ​

query ​

SelectQuery

The query to append with INTERSECT

Returns ​

BinarySelectQuery

A new BinarySelectQuery representing "(this) INTERSECT query"


intersectAll() ​

intersectAll(query): BinarySelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:93

Appends another query to this binary query using INTERSECT ALL as the operator. This creates a new BinarySelectQuery where the left side is this binary query and the right side is the provided query.

Parameters ​

query ​

SelectQuery

The query to append with INTERSECT ALL

Returns ​

BinarySelectQuery

A new BinarySelectQuery representing "(this) INTERSECT ALL query"


except() ​

except(query): BinarySelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:105

Appends another query to this binary query using EXCEPT as the operator. This creates a new BinarySelectQuery where the left side is this binary query and the right side is the provided query.

Parameters ​

query ​

SelectQuery

The query to append with EXCEPT

Returns ​

BinarySelectQuery

A new BinarySelectQuery representing "(this) EXCEPT query"


exceptAll() ​

exceptAll(query): BinarySelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:117

Appends another query to this binary query using EXCEPT ALL as the operator. This creates a new BinarySelectQuery where the left side is this binary query and the right side is the provided query.

Parameters ​

query ​

SelectQuery

The query to append with EXCEPT ALL

Returns ​

BinarySelectQuery

A new BinarySelectQuery representing "(this) EXCEPT ALL query"


appendSelectQuery() ​

appendSelectQuery(operator, query): BinarySelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:130

Appends another query to this binary query using the specified operator. This creates a new BinarySelectQuery where the left side is this binary query and the right side is the provided query.

Parameters ​

operator ​

string

SQL operator to use (e.g. 'union', 'union all', 'intersect', 'except')

query ​

SelectQuery

The query to append with the specified operator

Returns ​

BinarySelectQuery

A new BinarySelectQuery representing "(this) [operator] query"


unionRaw() ​

unionRaw(sql): BinarySelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:146

Appends another query to this binary query using UNION as the operator, accepting a raw SQL string. This method parses the SQL string and appends the resulting query using UNION.

Parameters ​

sql ​

string

The SQL string to parse and union

Returns ​

BinarySelectQuery

A new BinarySelectQuery representing "(this) UNION (parsed query)"


unionAllRaw() ​

unionAllRaw(sql): BinarySelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:150

Parameters ​

sql ​

string

Returns ​

BinarySelectQuery


intersectRaw() ​

intersectRaw(sql): BinarySelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:154

Parameters ​

sql ​

string

Returns ​

BinarySelectQuery


intersectAllRaw() ​

intersectAllRaw(sql): BinarySelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:158

Parameters ​

sql ​

string

Returns ​

BinarySelectQuery


exceptRaw() ​

exceptRaw(sql): BinarySelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:162

Parameters ​

sql ​

string

Returns ​

BinarySelectQuery


exceptAllRaw() ​

exceptAllRaw(sql): BinarySelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:166

Parameters ​

sql ​

string

Returns ​

BinarySelectQuery


toInsertQuery() ​

toInsertQuery(options): InsertQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:175

Converts this query into an INSERT statement definition.

Parameters ​

options ​

InsertQueryConversionOptions

Returns ​

InsertQuery

Remarks ​

The underlying simple query may be reordered so that column order matches the requested insert columns.

Implementation of ​

SelectQuery.toInsertQuery


toUpdateQuery() ​

toUpdateQuery(options): UpdateQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:183

Converts this query into an UPDATE statement definition.

Parameters ​

options ​

UpdateQueryConversionOptions

Returns ​

UpdateQuery

Remarks ​

The conversion can reorder the SELECT list produced by toSimpleQuery.

Implementation of ​

SelectQuery.toUpdateQuery


toDeleteQuery() ​

toDeleteQuery(options): DeleteQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:191

Converts this query into a DELETE statement definition.

Parameters ​

options ​

DeleteQueryConversionOptions

Returns ​

DeleteQuery

Remarks ​

The conversion can reorder the SELECT list produced by toSimpleQuery.

Implementation of ​

SelectQuery.toDeleteQuery


toMergeQuery() ​

toMergeQuery(options): MergeQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:199

Converts this query into a MERGE statement definition.

Parameters ​

options ​

MergeQueryConversionOptions

Returns ​

MergeQuery

Remarks ​

The conversion can reorder the SELECT list produced by toSimpleQuery.

Implementation of ​

SelectQuery.toMergeQuery


toSource() ​

toSource(alias): SourceExpression

Defined in: packages/core/src/models/BinarySelectQuery.ts:205

Parameters ​

alias ​

string = "subq"

Returns ​

SourceExpression


setParameter() ​

setParameter(name, value): this

Defined in: packages/core/src/models/BinarySelectQuery.ts:217

Sets the value of a parameter by name in this query.

Parameters ​

name ​

string

Parameter name

value ​

SqlParameterValue

Value to set

Returns ​

this

Implementation of ​

SelectQuery.setParameter


toSimpleQuery() ​

toSimpleQuery(): SimpleSelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:227

Converts this BinarySelectQuery to a SimpleSelectQuery using QueryBuilder. This enables CTE management on binary queries by wrapping them as subqueries.

Returns ​

SimpleSelectQuery

A SimpleSelectQuery representation of this binary query

Implementation of ​

SelectQuery.toSimpleQuery


getKind() ​

getKind(): symbol

Defined in: packages/core/src/models/SqlComponent.ts:15

Returns ​

symbol

Implementation of ​

SelectQuery.getKind

Inherited from ​

SqlComponent.getKind


accept() ​

accept<T&gt;(visitor): T

Defined in: packages/core/src/models/SqlComponent.ts:19

Type Parameters ​

T ​

T

Parameters ​

visitor ​

SqlComponentVisitor<T&gt;

Returns ​

T

Implementation of ​

SelectQuery.accept

Inherited from ​

SqlComponent.accept


toSqlString() ​

toSqlString(formatter): string

Defined in: packages/core/src/models/SqlComponent.ts:23

Parameters ​

formatter ​

SqlComponentVisitor<string&gt;

Returns ​

string

Implementation of ​

SelectQuery.toSqlString

Inherited from ​

SqlComponent.toSqlString


addPositionedComments() ​

addPositionedComments(position, comments): void

Defined in: packages/core/src/models/SqlComponent.ts:37

Add comments at a specific position

Parameters ​

position ​

"before" | "after"

comments ​

string[]

Returns ​

void

Implementation of ​

SelectQuery.addPositionedComments

Inherited from ​

SqlComponent.addPositionedComments


getPositionedComments() ​

getPositionedComments(position): string[]

Defined in: packages/core/src/models/SqlComponent.ts:56

Get comments for a specific position

Parameters ​

position ​

"before" | "after"

Returns ​

string[]

Implementation of ​

SelectQuery.getPositionedComments

Inherited from ​

SqlComponent.getPositionedComments


getAllPositionedComments() ​

getAllPositionedComments(): string[]

Defined in: packages/core/src/models/SqlComponent.ts:66

Get all positioned comments as a flat array in order (before, after)

Returns ​

string[]

Implementation of ​

SelectQuery.getAllPositionedComments

Inherited from ​

SqlComponent.getAllPositionedComments

Released under the MIT License.