Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5430,6 +5430,151 @@ impl Spanned for AlterFunction {
}
}

/// PostgreSQL text search object kind.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// PostgreSQL text search object kind.
/// Text search object kind.

Can we instead add a [PostgreSQL] link to the reference docs. We can avoid mentioning a specific dialect as part of the main description (it goes stale quickly/immediately if there are other dialects that support the feature)

#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum TextSearchObjectType {
/// `DICTIONARY`
Dictionary,
/// `CONFIGURATION`
Configuration,
/// `TEMPLATE`
Template,
/// `PARSER`
Parser,
}

impl fmt::Display for TextSearchObjectType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
TextSearchObjectType::Dictionary => write!(f, "DICTIONARY"),
TextSearchObjectType::Configuration => write!(f, "CONFIGURATION"),
TextSearchObjectType::Template => write!(f, "TEMPLATE"),
TextSearchObjectType::Parser => write!(f, "PARSER"),
}
}
}

/// PostgreSQL `CREATE TEXT SEARCH ...` statement.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// PostgreSQL `CREATE TEXT SEARCH ...` statement.
/// `CREATE TEXT SEARCH ...` statement.

same comment regarding doc link

#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct CreateTextSearch {
/// The specific text search object type.
pub object_type: TextSearchObjectType,
/// Object name.
pub name: ObjectName,
/// Parenthesized options.
pub options: Vec<SqlOption>,
}

impl fmt::Display for CreateTextSearch {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"CREATE TEXT SEARCH {} {} ({})",
self.object_type,
self.name,
display_comma_separated(&self.options)
)
}
}

impl Spanned for CreateTextSearch {
fn span(&self) -> Span {
Span::empty()
}
}

/// Option assignment used by `ALTER TEXT SEARCH DICTIONARY ... ( ... )`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a link to the docs for this struct?

#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct AlterTextSearchDictionaryOption {
/// Option name.
pub key: Ident,
/// Optional value (`option [= value]`).
pub value: Option<Expr>,
}

impl fmt::Display for AlterTextSearchDictionaryOption {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self.value {
Some(value) => write!(f, "{} = {}", self.key, value),
None => write!(f, "{}", self.key),
}
}
}

/// Operation for PostgreSQL `ALTER TEXT SEARCH ...`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Operation for PostgreSQL `ALTER TEXT SEARCH ...`.
/// Operation for `ALTER TEXT SEARCH ...`.

same comment regarding doc link

#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum AlterTextSearchOperation {
/// `RENAME TO new_name`
RenameTo {
/// New name.
new_name: Ident,
},
/// `OWNER TO ...`
OwnerTo(Owner),
/// `SET SCHEMA schema_name`
SetSchema {
/// Target schema.
schema_name: ObjectName,
},
/// `( option [= value] [, ...] )`
SetOptions {
/// Dictionary options to apply.
options: Vec<AlterTextSearchDictionaryOption>,
},
}

impl fmt::Display for AlterTextSearchOperation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
AlterTextSearchOperation::RenameTo { new_name } => write!(f, "RENAME TO {new_name}"),
AlterTextSearchOperation::OwnerTo(owner) => write!(f, "OWNER TO {owner}"),
AlterTextSearchOperation::SetSchema { schema_name } => {
write!(f, "SET SCHEMA {schema_name}")
}
AlterTextSearchOperation::SetOptions { options } => {
write!(f, "({})", display_comma_separated(options))
}
}
}
}

/// PostgreSQL `ALTER TEXT SEARCH ...` statement.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// PostgreSQL `ALTER TEXT SEARCH ...` statement.
/// `ALTER TEXT SEARCH ...` statement.

same comment regarding doc link

#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct AlterTextSearch {
/// The specific text search object type.
pub object_type: TextSearchObjectType,
/// Object name.
pub name: ObjectName,
/// Operation to apply.
pub operation: AlterTextSearchOperation,
}

impl fmt::Display for AlterTextSearch {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"ALTER TEXT SEARCH {} {} {}",
self.object_type, self.name, self.operation
)
}
}

impl Spanned for AlterTextSearch {
fn span(&self) -> Span {
Span::empty()
}
}

/// CREATE POLICY statement.
///
/// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-createpolicy.html)
Expand Down
51 changes: 38 additions & 13 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,24 @@ pub use self::ddl::{
AlterOperatorClass, AlterOperatorClassOperation, AlterOperatorFamily,
AlterOperatorFamilyOperation, AlterOperatorOperation, AlterPolicy, AlterPolicyOperation,
AlterSchema, AlterSchemaOperation, AlterTable, AlterTableAlgorithm, AlterTableLock,
AlterTableOperation, AlterTableType, AlterType, AlterTypeAddValue, AlterTypeAddValuePosition,
AlterTableOperation, AlterTableType, AlterTextSearch, AlterTextSearchDictionaryOption,
AlterTextSearchOperation, AlterType, AlterTypeAddValue, AlterTypeAddValuePosition,
AlterTypeOperation, AlterTypeRename, AlterTypeRenameValue, ClusteredBy, ColumnDef,
ColumnOption, ColumnOptionDef, ColumnOptions, ColumnPolicy, ColumnPolicyProperty,
ConstraintCharacteristics, CreateConnector, CreateDomain, CreateExtension, CreateFunction,
CreateIndex, CreateOperator, CreateOperatorClass, CreateOperatorFamily, CreatePolicy,
CreatePolicyCommand, CreatePolicyType, CreateTable, CreateTrigger, CreateView, Deduplicate,
DeferrableInitial, DistStyle, DropBehavior, DropExtension, DropFunction, DropOperator,
DropOperatorClass, DropOperatorFamily, DropOperatorSignature, DropPolicy, DropTrigger,
ForValues, FunctionReturnType, GeneratedAs, GeneratedExpressionMode, IdentityParameters,
IdentityProperty, IdentityPropertyFormatKind, IdentityPropertyKind, IdentityPropertyOrder,
IndexColumn, IndexOption, IndexType, KeyOrIndexDisplay, Msck, NullsDistinctOption,
OperatorArgTypes, OperatorClassItem, OperatorFamilyDropItem, OperatorFamilyItem,
OperatorOption, OperatorPurpose, Owner, Partition, PartitionBoundValue, ProcedureParam,
ReferentialAction, RenameTableNameKind, ReplicaIdentity, TagsColumnOption, TriggerObjectKind,
Truncate, UserDefinedTypeCompositeAttributeDef, UserDefinedTypeInternalLength,
UserDefinedTypeRangeOption, UserDefinedTypeRepresentation, UserDefinedTypeSqlDefinitionOption,
UserDefinedTypeStorage, ViewColumnDef,
CreatePolicyCommand, CreatePolicyType, CreateTable, CreateTextSearch, CreateTrigger,
CreateView, Deduplicate, DeferrableInitial, DistStyle, DropBehavior, DropExtension,
DropFunction, DropOperator, DropOperatorClass, DropOperatorFamily, DropOperatorSignature,
DropPolicy, DropTrigger, ForValues, FunctionReturnType, GeneratedAs, GeneratedExpressionMode,
IdentityParameters, IdentityProperty, IdentityPropertyFormatKind, IdentityPropertyKind,
IdentityPropertyOrder, IndexColumn, IndexOption, IndexType, KeyOrIndexDisplay, Msck,
NullsDistinctOption, OperatorArgTypes, OperatorClassItem, OperatorFamilyDropItem,
OperatorFamilyItem, OperatorOption, OperatorPurpose, Owner, Partition, PartitionBoundValue,
ProcedureParam, ReferentialAction, RenameTableNameKind, ReplicaIdentity, TagsColumnOption,
TextSearchObjectType, TriggerObjectKind, Truncate, UserDefinedTypeCompositeAttributeDef,
UserDefinedTypeInternalLength, UserDefinedTypeRangeOption, UserDefinedTypeRepresentation,
UserDefinedTypeSqlDefinitionOption, UserDefinedTypeStorage, ViewColumnDef,
};
pub use self::dml::{
Delete, Insert, Merge, MergeAction, MergeClause, MergeClauseKind, MergeInsertExpr,
Expand Down Expand Up @@ -3720,6 +3721,11 @@ pub enum Statement {
/// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-createopclass.html)
CreateOperatorClass(CreateOperatorClass),
/// ```sql
/// CREATE TEXT SEARCH { DICTIONARY | CONFIGURATION | TEMPLATE | PARSER }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// CREATE TEXT SEARCH { DICTIONARY | CONFIGURATION | TEMPLATE | PARSER }
/// A `CREATE TEXT SEARCH` statement

/// ```
/// See [PostgreSQL](https://www.postgresql.org/docs/current/textsearch-intro.html)
CreateTextSearch(CreateTextSearch),
/// ```sql
/// ALTER TABLE
/// ```
AlterTable(AlterTable),
Expand Down Expand Up @@ -3779,6 +3785,11 @@ pub enum Statement {
/// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-alteropclass.html)
AlterOperatorClass(AlterOperatorClass),
/// ```sql
/// ALTER TEXT SEARCH { DICTIONARY | CONFIGURATION | TEMPLATE | PARSER }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// ALTER TEXT SEARCH { DICTIONARY | CONFIGURATION | TEMPLATE | PARSER }
/// A `ALTER TEXT SEARCH` statement

/// ```
/// See [PostgreSQL](https://www.postgresql.org/docs/current/textsearch-configuration.html)
AlterTextSearch(AlterTextSearch),
/// ```sql
/// ALTER ROLE
/// ```
AlterRole {
Expand Down Expand Up @@ -5484,6 +5495,7 @@ impl fmt::Display for Statement {
create_operator_family.fmt(f)
}
Statement::CreateOperatorClass(create_operator_class) => create_operator_class.fmt(f),
Statement::CreateTextSearch(create_text_search) => create_text_search.fmt(f),
Statement::AlterTable(alter_table) => write!(f, "{alter_table}"),
Statement::AlterIndex { name, operation } => {
write!(f, "ALTER INDEX {name} {operation}")
Expand Down Expand Up @@ -5514,6 +5526,7 @@ impl fmt::Display for Statement {
Statement::AlterOperatorClass(alter_operator_class) => {
write!(f, "{alter_operator_class}")
}
Statement::AlterTextSearch(alter_text_search) => write!(f, "{alter_text_search}"),
Statement::AlterRole { name, operation } => {
write!(f, "ALTER ROLE {name} {operation}")
}
Expand Down Expand Up @@ -12107,6 +12120,12 @@ impl From<CreateOperatorClass> for Statement {
}
}

impl From<CreateTextSearch> for Statement {
fn from(c: CreateTextSearch) -> Self {
Self::CreateTextSearch(c)
}
}

impl From<AlterSchema> for Statement {
fn from(a: AlterSchema) -> Self {
Self::AlterSchema(a)
Expand Down Expand Up @@ -12143,6 +12162,12 @@ impl From<AlterOperatorClass> for Statement {
}
}

impl From<AlterTextSearch> for Statement {
fn from(a: AlterTextSearch) -> Self {
Self::AlterTextSearch(a)
}
}

impl From<Merge> for Statement {
fn from(m: Merge) -> Self {
Self::Merge(m)
Expand Down
2 changes: 2 additions & 0 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ impl Spanned for Statement {
create_operator_family.span()
}
Statement::CreateOperatorClass(create_operator_class) => create_operator_class.span(),
Statement::CreateTextSearch(create_text_search) => create_text_search.span(),
Statement::AlterTable(alter_table) => alter_table.span(),
Statement::AlterIndex { name, operation } => name.span().union(&operation.span()),
Statement::AlterView {
Expand All @@ -408,6 +409,7 @@ impl Spanned for Statement {
Statement::AlterOperator { .. } => Span::empty(),
Statement::AlterOperatorFamily { .. } => Span::empty(),
Statement::AlterOperatorClass { .. } => Span::empty(),
Statement::AlterTextSearch { .. } => Span::empty(),
Statement::AlterRole { .. } => Span::empty(),
Statement::AlterSession { .. } => Span::empty(),
Statement::AttachDatabase { .. } => Span::empty(),
Expand Down
4 changes: 4 additions & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ define_keywords!(
COMPUTE,
CONCURRENTLY,
CONDITION,
CONFIGURATION,
CONFLICT,
CONNECT,
CONNECTION,
Expand Down Expand Up @@ -332,6 +333,7 @@ define_keywords!(
DETACH,
DETAIL,
DETERMINISTIC,
DICTIONARY,
DIMENSIONS,
DIRECTORY,
DISABLE,
Expand Down Expand Up @@ -764,6 +766,7 @@ define_keywords!(
PARALLEL,
PARAMETER,
PARQUET,
PARSER,
PART,
PARTIAL,
PARTITION,
Expand Down Expand Up @@ -1034,6 +1037,7 @@ define_keywords!(
TASK,
TBLPROPERTIES,
TEMP,
TEMPLATE,
TEMPORARY,
TEMPTABLE,
TERMINATED,
Expand Down
Loading
Loading