Skip to main content

Select

Struct Select 

Source
pub struct Select {
Show 36 fields pub expressions: Vec<Expression>, pub from: Option<From>, pub joins: Vec<Join>, pub lateral_views: Vec<LateralView>, pub prewhere: Option<Expression>, pub where_clause: Option<Where>, pub group_by: Option<GroupBy>, pub having: Option<Having>, pub qualify: Option<Qualify>, pub order_by: Option<OrderBy>, pub distribute_by: Option<DistributeBy>, pub cluster_by: Option<ClusterBy>, pub sort_by: Option<SortBy>, pub limit: Option<Limit>, pub offset: Option<Offset>, pub limit_by: Option<Vec<Expression>>, pub fetch: Option<Fetch>, pub distinct: bool, pub distinct_on: Option<Vec<Expression>>, pub top: Option<Top>, pub with: Option<With>, pub sample: Option<Sample>, pub settings: Option<Vec<Expression>>, pub format: Option<Expression>, pub windows: Option<Vec<NamedWindow>>, pub hint: Option<Hint>, pub connect: Option<Connect>, pub into: Option<SelectInto>, pub locks: Vec<Lock>, pub for_xml: Vec<Expression>, pub leading_comments: Vec<String>, pub post_select_comments: Vec<String>, pub kind: Option<String>, pub operation_modifiers: Vec<String>, pub qualify_after_window: bool, pub option: Option<String>,
}
Expand description

Represent a complete SELECT statement.

This is the most feature-rich AST node, covering the full surface area of SELECT syntax across 30+ SQL dialects. Fields that are Option or empty Vec are omitted from the generated SQL when absent.

§Key Fields

  • expressions – the select-list (columns, *, computed expressions).
  • from – the FROM clause. None for SELECT 1 style queries.
  • joins – zero or more JOIN clauses, each with a JoinKind.
  • where_clause – the WHERE predicate.
  • group_by – GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
  • having – HAVING predicate.
  • order_by – ORDER BY with ASC/DESC and NULLS FIRST/LAST.
  • limit / offset / fetch – result set limiting.
  • with – Common Table Expressions (CTEs).
  • distinct / distinct_on – DISTINCT and PostgreSQL DISTINCT ON.
  • windows – named window definitions (WINDOW w AS …).

Dialect-specific extensions are supported via fields like prewhere (ClickHouse), qualify (Snowflake/BigQuery/DuckDB), connect (Oracle CONNECT BY), for_xml (TSQL), and settings (ClickHouse).

Fields§

§expressions: Vec<Expression>

The select-list: columns, expressions, aliases, and wildcards.

§from: Option<From>

The FROM clause, containing one or more table sources.

§joins: Vec<Join>

JOIN clauses applied after the FROM source.

§lateral_views: Vec<LateralView>§prewhere: Option<Expression>

ClickHouse PREWHERE clause

§where_clause: Option<Where>§group_by: Option<GroupBy>§having: Option<Having>§qualify: Option<Qualify>§order_by: Option<OrderBy>§distribute_by: Option<DistributeBy>§cluster_by: Option<ClusterBy>§sort_by: Option<SortBy>§limit: Option<Limit>§offset: Option<Offset>§limit_by: Option<Vec<Expression>>

ClickHouse LIMIT BY clause expressions

§fetch: Option<Fetch>§distinct: bool§distinct_on: Option<Vec<Expression>>§top: Option<Top>§with: Option<With>§sample: Option<Sample>§settings: Option<Vec<Expression>>

ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)

§format: Option<Expression>

ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)

§windows: Option<Vec<NamedWindow>>§hint: Option<Hint>§connect: Option<Connect>

Oracle CONNECT BY clause for hierarchical queries

§into: Option<SelectInto>

SELECT … INTO table_name for creating tables

§locks: Vec<Lock>

FOR UPDATE/SHARE locking clauses

§for_xml: Vec<Expression>

T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)

§leading_comments: Vec<String>

Leading comments before the statement

§post_select_comments: Vec<String>

Comments that appear after SELECT keyword (before expressions) e.g., SELECT /hint/ col -> post_select_comments: [“/hint/”]

§kind: Option<String>

BigQuery SELECT AS STRUCT / SELECT AS VALUE kind

§operation_modifiers: Vec<String>

MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)

§qualify_after_window: bool

Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)

§option: Option<String>

TSQL OPTION clause (e.g., OPTION(LABEL = ‘foo’))

Implementations§

Source§

impl Select

Source

pub fn new() -> Self

Source

pub fn column(self, expr: Expression) -> Self

Add a column to select

Source

pub fn from(self, table: Expression) -> Self

Set the FROM clause

Source

pub fn where_(self, condition: Expression) -> Self

Add a WHERE clause

Source

pub fn distinct(self) -> Self

Set DISTINCT

Source

pub fn join(self, join: Join) -> Self

Add a JOIN

Source

pub fn order_by(self, expressions: Vec<Ordered>) -> Self

Set ORDER BY

Source

pub fn limit(self, n: Expression) -> Self

Set LIMIT

Source

pub fn offset(self, n: Expression) -> Self

Set OFFSET

Trait Implementations§

Source§

impl Clone for Select

Source§

fn clone(&self) -> Select

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Select

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Select

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Select

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Select

Source§

fn eq(&self, other: &Select) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Select

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Select

Auto Trait Implementations§

§

impl Freeze for Select

§

impl RefUnwindSafe for Select

§

impl Send for Select

§

impl Sync for Select

§

impl Unpin for Select

§

impl UnwindSafe for Select

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,