diesel/query_builder/select_statement/
dsl_impls.rs

1use super::BoxedSelectStatement;
2use crate::associations::HasTable;
3use crate::backend::Backend;
4use crate::dsl::AsExprOf;
5use crate::expression::nullable::Nullable;
6use crate::expression::*;
7use crate::insertable::Insertable;
8use crate::query_builder::combination_clause::*;
9use crate::query_builder::distinct_clause::*;
10use crate::query_builder::from_clause::AsQuerySource;
11use crate::query_builder::from_clause::FromClause;
12use crate::query_builder::group_by_clause::*;
13use crate::query_builder::insert_statement::InsertFromSelect;
14use crate::query_builder::limit_clause::*;
15use crate::query_builder::limit_offset_clause::{BoxedLimitOffsetClause, LimitOffsetClause};
16use crate::query_builder::locking_clause::*;
17use crate::query_builder::offset_clause::*;
18use crate::query_builder::order_clause::*;
19use crate::query_builder::select_clause::*;
20use crate::query_builder::update_statement::target::*;
21use crate::query_builder::where_clause::*;
22use crate::query_builder::NoFromClause;
23use crate::query_builder::{
24    AsQuery, IntoBoxedClause, Query, QueryFragment, SelectQuery, SelectStatement,
25};
26use crate::query_dsl::group_by_dsl::ValidDistinctForGroupBy;
27use crate::query_dsl::methods::*;
28use crate::query_dsl::order_dsl::ValidOrderingForDistinct;
29use crate::query_dsl::*;
30use crate::query_source::joins::{Join, JoinOn, JoinTo};
31use crate::query_source::QuerySource;
32use crate::sql_types::{BigInt, BoolOrNullableBool};
33
34impl<F, D, W, O, LOf, G, H, LC, Rhs, Kind, On> InternalJoinDsl<Rhs, Kind, On>
35    for SelectStatement<FromClause<F>, DefaultSelectClause<FromClause<F>>, D, W, O, LOf, G, H, LC>
36where
37    F: QuerySource,
38    Rhs: QuerySource,
39    JoinOn<Join<F, Rhs, Kind>, On>: QuerySource,
40    SelectStatement<
41        FromClause<JoinOn<Join<F, Rhs, Kind>, On>>,
42        DefaultSelectClause<FromClause<JoinOn<Join<F, Rhs, Kind>, On>>>,
43        D,
44        W,
45        O,
46        LOf,
47        G,
48        H,
49        LC,
50    >: AsQuery,
51{
52    type Output = SelectStatement<
53        FromClause<JoinOn<Join<F, Rhs, Kind>, On>>,
54        DefaultSelectClause<FromClause<JoinOn<Join<F, Rhs, Kind>, On>>>,
55        D,
56        W,
57        O,
58        LOf,
59        G,
60        H,
61        LC,
62    >;
63
64    fn join(self, rhs: Rhs, kind: Kind, on: On) -> Self::Output {
65        let from = FromClause::new(Join::new(self.from.source, rhs, kind).on(on));
66        SelectStatement::new(
67            DefaultSelectClause::new(&from),
68            from,
69            self.distinct,
70            self.where_clause,
71            self.order,
72            self.limit_offset,
73            self.group_by,
74            self.having,
75            self.locking,
76        )
77    }
78}
79
80impl<F, S, D, W, O, LOf, G, H, LC, Rhs, Kind, On> InternalJoinDsl<Rhs, Kind, On>
81    for SelectStatement<FromClause<F>, SelectClause<S>, D, W, O, LOf, G, H, LC>
82where
83    F: QuerySource,
84    Rhs: QuerySource,
85    JoinOn<Join<F, Rhs, Kind>, On>: QuerySource,
86    SelectStatement<
87        FromClause<JoinOn<Join<F, Rhs, Kind>, On>>,
88        SelectClause<S>,
89        D,
90        W,
91        O,
92        LOf,
93        G,
94        H,
95        LC,
96    >: AsQuery,
97{
98    type Output = SelectStatement<
99        FromClause<JoinOn<Join<F, Rhs, Kind>, On>>,
100        SelectClause<S>,
101        D,
102        W,
103        O,
104        LOf,
105        G,
106        H,
107        LC,
108    >;
109
110    fn join(self, rhs: Rhs, kind: Kind, on: On) -> Self::Output {
111        SelectStatement::new(
112            self.select,
113            FromClause::new(Join::new(self.from.source, rhs, kind).on(on)),
114            self.distinct,
115            self.where_clause,
116            self.order,
117            self.limit_offset,
118            self.group_by,
119            self.having,
120            self.locking,
121        )
122    }
123}
124
125impl<F, S, D, W, O, LOf, G, H, LC, Selection> SelectDsl<Selection>
126    for SelectStatement<FromClause<F>, S, D, W, O, LOf, G, H, LC>
127where
128    G: ValidGroupByClause,
129    F: QuerySource,
130    Selection: SelectableExpression<F> + ValidGrouping<G::Expressions>,
131    SelectStatement<FromClause<F>, SelectClause<Selection>, D, W, O, LOf, G, H, LC>: SelectQuery,
132    D: ValidDistinctForGroupBy<Selection, G::Expressions>,
133{
134    type Output = SelectStatement<FromClause<F>, SelectClause<Selection>, D, W, O, LOf, G, H, LC>;
135
136    fn select(self, selection: Selection) -> Self::Output {
137        SelectStatement::new(
138            SelectClause(selection),
139            self.from,
140            self.distinct,
141            self.where_clause,
142            self.order,
143            self.limit_offset,
144            self.group_by,
145            self.having,
146            self.locking,
147        )
148    }
149}
150
151impl<S, D, W, O, LOf, G, H, LC, Selection> SelectDsl<Selection>
152    for SelectStatement<NoFromClause, S, D, W, O, LOf, G, H, LC>
153where
154    G: ValidGroupByClause,
155    Selection: SelectableExpression<NoFromClause> + ValidGrouping<G::Expressions>,
156    SelectStatement<NoFromClause, SelectClause<Selection>, D, W, O, LOf, G, H, LC>: SelectQuery,
157    D: ValidDistinctForGroupBy<Selection, G::Expressions>,
158{
159    type Output = SelectStatement<NoFromClause, SelectClause<Selection>, D, W, O, LOf, G, H, LC>;
160
161    fn select(self, selection: Selection) -> Self::Output {
162        SelectStatement::new(
163            SelectClause(selection),
164            self.from,
165            self.distinct,
166            self.where_clause,
167            self.order,
168            self.limit_offset,
169            self.group_by,
170            self.having,
171            self.locking,
172        )
173    }
174}
175
176impl<ST, F, S, D, W, O, LOf, G, H> DistinctDsl for SelectStatement<F, S, D, W, O, LOf, G, H>
177where
178    Self: SelectQuery<SqlType = ST>,
179    SelectStatement<F, S, DistinctClause, W, O, LOf, G, H>: SelectQuery<SqlType = ST>,
180{
181    type Output = SelectStatement<F, S, DistinctClause, W, O, LOf, G, H>;
182
183    fn distinct(self) -> Self::Output {
184        SelectStatement::new(
185            self.select,
186            self.from,
187            DistinctClause,
188            self.where_clause,
189            self.order,
190            self.limit_offset,
191            self.group_by,
192            self.having,
193            self.locking,
194        )
195    }
196}
197
198impl<F, S, D, W, O, LOf, G, H, LC, Predicate> FilterDsl<Predicate>
199    for SelectStatement<F, S, D, W, O, LOf, G, H, LC>
200where
201    Predicate: Expression + NonAggregate,
202    Predicate::SqlType: BoolOrNullableBool,
203    W: WhereAnd<Predicate>,
204{
205    type Output = SelectStatement<F, S, D, W::Output, O, LOf, G, H, LC>;
206
207    fn filter(self, predicate: Predicate) -> Self::Output {
208        SelectStatement::new(
209            self.select,
210            self.from,
211            self.distinct,
212            self.where_clause.and(predicate),
213            self.order,
214            self.limit_offset,
215            self.group_by,
216            self.having,
217            self.locking,
218        )
219    }
220}
221
222impl<F, S, D, W, O, LOf, G, H, LC, Predicate> OrFilterDsl<Predicate>
223    for SelectStatement<F, S, D, W, O, LOf, G, H, LC>
224where
225    Predicate: Expression + NonAggregate,
226    Predicate::SqlType: BoolOrNullableBool,
227    W: WhereOr<Predicate>,
228{
229    type Output = SelectStatement<F, S, D, W::Output, O, LOf, G, H, LC>;
230
231    fn or_filter(self, predicate: Predicate) -> Self::Output {
232        SelectStatement::new(
233            self.select,
234            self.from,
235            self.distinct,
236            self.where_clause.or(predicate),
237            self.order,
238            self.limit_offset,
239            self.group_by,
240            self.having,
241            self.locking,
242        )
243    }
244}
245
246use crate::dsl::Filter;
247use crate::expression_methods::EqAll;
248use crate::query_builder::having_clause::{HavingClause, NoHavingClause};
249use crate::query_source::Table;
250
251impl<F, S, D, W, O, LOf, G, H, LC, PK> FindDsl<PK>
252    for SelectStatement<FromClause<F>, S, D, W, O, LOf, G, H, LC>
253where
254    F: Table,
255    F::PrimaryKey: EqAll<PK>,
256    Self: FilterDsl<<F::PrimaryKey as EqAll<PK>>::Output>,
257{
258    type Output = Filter<Self, <F::PrimaryKey as EqAll<PK>>::Output>;
259
260    fn find(self, id: PK) -> Self::Output {
261        let primary_key = self.from.source.primary_key();
262        FilterDsl::filter(self, primary_key.eq_all(id))
263    }
264}
265
266// no impls for `NoFromClause` here because order is not really supported there yet
267impl<ST, F, S, D, W, O, LOf, G, H, LC, Expr> OrderDsl<Expr>
268    for SelectStatement<FromClause<F>, S, D, W, O, LOf, G, H, LC>
269where
270    F: QuerySource,
271    Expr: AppearsOnTable<F>,
272    Self: SelectQuery<SqlType = ST>,
273    SelectStatement<FromClause<F>, S, D, W, OrderClause<Expr>, LOf, G, H, LC>:
274        SelectQuery<SqlType = ST>,
275    OrderClause<Expr>: ValidOrderingForDistinct<D>,
276{
277    type Output = SelectStatement<FromClause<F>, S, D, W, OrderClause<Expr>, LOf, G, H, LC>;
278
279    fn order(self, expr: Expr) -> Self::Output {
280        let order = OrderClause(expr);
281        SelectStatement::new(
282            self.select,
283            self.from,
284            self.distinct,
285            self.where_clause,
286            order,
287            self.limit_offset,
288            self.group_by,
289            self.having,
290            self.locking,
291        )
292    }
293}
294
295impl<F, S, D, W, O, LOf, G, H, LC, Expr> ThenOrderDsl<Expr>
296    for SelectStatement<FromClause<F>, S, D, W, OrderClause<O>, LOf, G, H, LC>
297where
298    F: QuerySource,
299    Expr: AppearsOnTable<F>,
300{
301    type Output = SelectStatement<FromClause<F>, S, D, W, OrderClause<(O, Expr)>, LOf, G, H, LC>;
302
303    fn then_order_by(self, expr: Expr) -> Self::Output {
304        SelectStatement::new(
305            self.select,
306            self.from,
307            self.distinct,
308            self.where_clause,
309            OrderClause((self.order.0, expr)),
310            self.limit_offset,
311            self.group_by,
312            self.having,
313            self.locking,
314        )
315    }
316}
317
318impl<F, S, D, W, LOf, G, LC, Expr> ThenOrderDsl<Expr>
319    for SelectStatement<F, S, D, W, NoOrderClause, LOf, G, LC>
320where
321    Expr: Expression,
322    Self: OrderDsl<Expr>,
323{
324    type Output = crate::dsl::Order<Self, Expr>;
325
326    fn then_order_by(self, expr: Expr) -> Self::Output {
327        self.order_by(expr)
328    }
329}
330
331#[doc(hidden)]
332type Limit = AsExprOf<i64, BigInt>;
333
334impl<ST, F, S, D, W, O, L, Of, G, H, LC> LimitDsl
335    for SelectStatement<F, S, D, W, O, LimitOffsetClause<L, Of>, G, H, LC>
336where
337    Self: SelectQuery<SqlType = ST>,
338    SelectStatement<F, S, D, W, O, LimitOffsetClause<LimitClause<Limit>, Of>, G, H, LC>:
339        SelectQuery<SqlType = ST>,
340{
341    type Output =
342        SelectStatement<F, S, D, W, O, LimitOffsetClause<LimitClause<Limit>, Of>, G, H, LC>;
343
344    fn limit(self, limit: i64) -> Self::Output {
345        let limit_clause = LimitClause(limit.into_sql::<BigInt>());
346        SelectStatement::new(
347            self.select,
348            self.from,
349            self.distinct,
350            self.where_clause,
351            self.order,
352            LimitOffsetClause {
353                limit_clause,
354                offset_clause: self.limit_offset.offset_clause,
355            },
356            self.group_by,
357            self.having,
358            self.locking,
359        )
360    }
361}
362
363#[doc(hidden)]
364type Offset = Limit;
365
366impl<ST, F, S, D, W, O, L, Of, G, H, LC> OffsetDsl
367    for SelectStatement<F, S, D, W, O, LimitOffsetClause<L, Of>, G, H, LC>
368where
369    Self: SelectQuery<SqlType = ST>,
370    SelectStatement<F, S, D, W, O, LimitOffsetClause<L, OffsetClause<Offset>>, G, H, LC>:
371        SelectQuery<SqlType = ST>,
372{
373    type Output =
374        SelectStatement<F, S, D, W, O, LimitOffsetClause<L, OffsetClause<Offset>>, G, H, LC>;
375
376    fn offset(self, offset: i64) -> Self::Output {
377        let offset_clause = OffsetClause(offset.into_sql::<BigInt>());
378        SelectStatement::new(
379            self.select,
380            self.from,
381            self.distinct,
382            self.where_clause,
383            self.order,
384            LimitOffsetClause {
385                limit_clause: self.limit_offset.limit_clause,
386                offset_clause,
387            },
388            self.group_by,
389            self.having,
390            self.locking,
391        )
392    }
393}
394
395impl<F, S, D, W, O, LOf, G, H, Expr> GroupByDsl<Expr> for SelectStatement<F, S, D, W, O, LOf, G, H>
396where
397    SelectStatement<F, S, D, W, O, LOf, GroupByClause<Expr>, H>: SelectQuery,
398    Expr: Expression + AppearsOnTable<F>,
399{
400    type Output = SelectStatement<F, S, D, W, O, LOf, GroupByClause<Expr>, H>;
401
402    fn group_by(self, expr: Expr) -> Self::Output {
403        let group_by = GroupByClause(expr);
404        SelectStatement::new(
405            self.select,
406            self.from,
407            self.distinct,
408            self.where_clause,
409            self.order,
410            self.limit_offset,
411            group_by,
412            self.having,
413            self.locking,
414        )
415    }
416}
417
418impl<F, S, W, O, LOf, Lock> LockingDsl<Lock>
419    for SelectStatement<F, S, NoDistinctClause, W, O, LOf>
420{
421    type Output = SelectStatement<
422        F,
423        S,
424        NoDistinctClause,
425        W,
426        O,
427        LOf,
428        NoGroupByClause,
429        NoHavingClause,
430        LockingClause<Lock, NoModifier>,
431    >;
432
433    fn with_lock(self, lock: Lock) -> Self::Output {
434        SelectStatement::new(
435            self.select,
436            self.from,
437            self.distinct,
438            self.where_clause,
439            self.order,
440            self.limit_offset,
441            self.group_by,
442            self.having,
443            LockingClause::new(lock, NoModifier),
444        )
445    }
446}
447
448impl<F, S, D, W, O, LOf, G, H, LC, LM, Modifier> ModifyLockDsl<Modifier>
449    for SelectStatement<F, S, D, W, O, LOf, G, H, LockingClause<LC, LM>>
450{
451    type Output = SelectStatement<F, S, D, W, O, LOf, G, H, LockingClause<LC, Modifier>>;
452
453    fn modify_lock(self, modifier: Modifier) -> Self::Output {
454        SelectStatement::new(
455            self.select,
456            self.from,
457            self.distinct,
458            self.where_clause,
459            self.order,
460            self.limit_offset,
461            self.group_by,
462            self.having,
463            LockingClause::new(self.locking.lock_mode, modifier),
464        )
465    }
466}
467
468impl<'a, F, S, D, W, O, LOf, G, H, DB> BoxedDsl<'a, DB>
469    for SelectStatement<FromClause<F>, S, D, W, O, LOf, G, H>
470where
471    Self: AsQuery,
472    DB: Backend,
473    F: QuerySource,
474    S: SelectClauseExpression<FromClause<F>> + QueryFragment<DB> + Send + 'a,
475    S::Selection: ValidGrouping<G::Expressions>,
476    D: QueryFragment<DB> + Send + 'a,
477    W: Into<BoxedWhereClause<'a, DB>>,
478    O: Into<Option<Box<dyn QueryFragment<DB> + Send + 'a>>>,
479    LOf: IntoBoxedClause<'a, DB, BoxedClause = BoxedLimitOffsetClause<'a, DB>>,
480    G: ValidGroupByClause + QueryFragment<DB> + Send + 'a,
481    H: QueryFragment<DB> + Send + 'a,
482{
483    type Output =
484        BoxedSelectStatement<'a, S::SelectClauseSqlType, FromClause<F>, DB, G::Expressions>;
485
486    fn internal_into_boxed(self) -> Self::Output {
487        BoxedSelectStatement::new(
488            self.select,
489            self.from,
490            Box::new(self.distinct),
491            self.where_clause.into(),
492            self.order.into(),
493            self.limit_offset.into_boxed(),
494            self.group_by,
495            Box::new(self.having),
496        )
497    }
498}
499
500impl<'a, S, D, W, O, LOf, G, H, DB> BoxedDsl<'a, DB>
501    for SelectStatement<NoFromClause, S, D, W, O, LOf, G, H>
502where
503    Self: AsQuery,
504    DB: Backend,
505    S: SelectClauseExpression<NoFromClause> + QueryFragment<DB> + Send + 'a,
506    S::Selection: ValidGrouping<G::Expressions>,
507    D: QueryFragment<DB> + Send + 'a,
508    W: Into<BoxedWhereClause<'a, DB>>,
509    O: Into<Option<Box<dyn QueryFragment<DB> + Send + 'a>>>,
510    LOf: IntoBoxedClause<'a, DB, BoxedClause = BoxedLimitOffsetClause<'a, DB>>,
511    G: ValidGroupByClause + QueryFragment<DB> + Send + 'a,
512    H: QueryFragment<DB> + Send + 'a,
513{
514    type Output =
515        BoxedSelectStatement<'a, S::SelectClauseSqlType, NoFromClause, DB, G::Expressions>;
516
517    fn internal_into_boxed(self) -> Self::Output {
518        BoxedSelectStatement::new_no_from_clause(
519            self.select,
520            self.from,
521            Box::new(self.distinct),
522            self.where_clause.into(),
523            self.order.into(),
524            self.limit_offset.into_boxed(),
525            self.group_by,
526            Box::new(self.having),
527        )
528    }
529}
530
531impl<F, S, D, W, O, LOf, G, H, LC> HasTable
532    for SelectStatement<FromClause<F>, S, D, W, O, LOf, G, H, LC>
533where
534    F: HasTable + QuerySource,
535{
536    type Table = F::Table;
537
538    fn table() -> Self::Table {
539        F::table()
540    }
541}
542
543impl<F, W> IntoUpdateTarget
544    for SelectStatement<FromClause<F>, DefaultSelectClause<FromClause<F>>, NoDistinctClause, W>
545where
546    F: QuerySource,
547    Self: HasTable,
548    W: ValidWhereClause<F>,
549{
550    type WhereClause = W;
551
552    fn into_update_target(self) -> UpdateTarget<Self::Table, Self::WhereClause> {
553        UpdateTarget {
554            table: Self::table(),
555            where_clause: self.where_clause,
556        }
557    }
558}
559
560// FIXME: Should we disable joining when `.group_by` has been called? Are there
561// any other query methods where a join no longer has the same semantics as
562// joining on just the table?
563impl<F, S, D, W, O, LOf, G, H, LC, Rhs> JoinTo<Rhs>
564    for SelectStatement<FromClause<F>, S, D, W, O, LOf, G, H, LC>
565where
566    F: JoinTo<Rhs> + QuerySource,
567{
568    type FromClause = <F as JoinTo<Rhs>>::FromClause;
569    type OnClause = F::OnClause;
570
571    fn join_target(rhs: Rhs) -> (Self::FromClause, Self::OnClause) {
572        F::join_target(rhs)
573    }
574}
575
576impl<F, S, D, W, O, LOf, G, H, LC> QueryDsl for SelectStatement<F, S, D, W, O, LOf, G, H, LC> {}
577
578impl<F, S, D, W, O, LOf, G, H, LC, Conn> RunQueryDsl<Conn>
579    for SelectStatement<F, S, D, W, O, LOf, G, H, LC>
580{
581}
582
583impl<F, S, D, W, O, LOf, G, H, LC, Tab> Insertable<Tab>
584    for SelectStatement<F, S, D, W, O, LOf, G, H, LC>
585where
586    Tab: Table,
587    Self: Query,
588    <Tab::AllColumns as ValidGrouping<()>>::IsAggregate:
589        MixedAggregates<is_aggregate::No, Output = is_aggregate::No>,
590{
591    type Values = InsertFromSelect<Self, Tab::AllColumns>;
592
593    fn values(self) -> Self::Values {
594        InsertFromSelect::new(self)
595    }
596}
597
598impl<F, S, D, W, O, LOf, G, H, LC, Tab> Insertable<Tab>
599    for &SelectStatement<F, S, D, W, O, LOf, G, H, LC>
600where
601    Tab: Table,
602    Self: Query,
603    <Tab::AllColumns as ValidGrouping<()>>::IsAggregate:
604        MixedAggregates<is_aggregate::No, Output = is_aggregate::No>,
605{
606    type Values = InsertFromSelect<Self, Tab::AllColumns>;
607
608    fn values(self) -> Self::Values {
609        InsertFromSelect::new(self)
610    }
611}
612
613impl<F, S, D, W, O, LOf, G, H> SelectNullableDsl
614    for SelectStatement<F, SelectClause<S>, D, W, O, LOf, G, H>
615{
616    type Output = SelectStatement<F, SelectClause<Nullable<S>>, D, W, O, LOf, G, H>;
617
618    fn nullable(self) -> Self::Output {
619        SelectStatement::new(
620            SelectClause(Nullable::new(self.select.0)),
621            self.from,
622            self.distinct,
623            self.where_clause,
624            self.order,
625            self.limit_offset,
626            self.group_by,
627            self.having,
628            self.locking,
629        )
630    }
631}
632
633impl<F, D, W, O, LOf, G, H> SelectNullableDsl
634    for SelectStatement<F, DefaultSelectClause<F>, D, W, O, LOf, G, H>
635where
636    F: AsQuerySource,
637{
638    type Output = SelectStatement<
639        F,
640        SelectClause<Nullable<<F::QuerySource as QuerySource>::DefaultSelection>>,
641        D,
642        W,
643        O,
644        LOf,
645        G,
646        H,
647    >;
648
649    fn nullable(self) -> Self::Output {
650        SelectStatement::new(
651            SelectClause(Nullable::new(
652                self.from.as_query_source().default_selection(),
653            )),
654            self.from,
655            self.distinct,
656            self.where_clause,
657            self.order,
658            self.limit_offset,
659            self.group_by,
660            self.having,
661            self.locking,
662        )
663    }
664}
665
666impl<F, S, D, W, O, LOf, G, H, Predicate> HavingDsl<Predicate>
667    for SelectStatement<FromClause<F>, S, D, W, O, LOf, GroupByClause<G>, H>
668where
669    F: QuerySource,
670    Predicate: AppearsOnTable<F>,
671    Predicate: Expression,
672    Predicate::SqlType: BoolOrNullableBool,
673{
674    type Output =
675        SelectStatement<FromClause<F>, S, D, W, O, LOf, GroupByClause<G>, HavingClause<Predicate>>;
676
677    fn having(self, predicate: Predicate) -> Self::Output {
678        SelectStatement::new(
679            self.select,
680            self.from,
681            self.distinct,
682            self.where_clause,
683            self.order,
684            self.limit_offset,
685            self.group_by,
686            HavingClause(predicate),
687            self.locking,
688        )
689    }
690}
691
692impl<F, S, D, W, O, LOf, G, H, LC> CombineDsl for SelectStatement<F, S, D, W, O, LOf, G, H, LC>
693where
694    Self: Query,
695{
696    type Query = Self;
697
698    fn union<Rhs>(self, rhs: Rhs) -> crate::dsl::Union<Self, Rhs>
699    where
700        Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
701    {
702        CombinationClause::new(Union, Distinct, self, rhs.as_query())
703    }
704
705    fn union_all<Rhs>(self, rhs: Rhs) -> crate::dsl::UnionAll<Self, Rhs>
706    where
707        Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
708    {
709        CombinationClause::new(Union, All, self, rhs.as_query())
710    }
711
712    fn intersect<Rhs>(self, rhs: Rhs) -> crate::dsl::Intersect<Self, Rhs>
713    where
714        Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
715    {
716        CombinationClause::new(Intersect, Distinct, self, rhs.as_query())
717    }
718
719    fn intersect_all<Rhs>(self, rhs: Rhs) -> crate::dsl::IntersectAll<Self, Rhs>
720    where
721        Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
722    {
723        CombinationClause::new(Intersect, All, self, rhs.as_query())
724    }
725
726    fn except<Rhs>(self, rhs: Rhs) -> crate::dsl::Except<Self, Rhs>
727    where
728        Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
729    {
730        CombinationClause::new(Except, Distinct, self, rhs.as_query())
731    }
732
733    fn except_all<Rhs>(self, rhs: Rhs) -> crate::dsl::ExceptAll<Self, Rhs>
734    where
735        Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
736    {
737        CombinationClause::new(Except, All, self, rhs.as_query())
738    }
739}