Skip to content

Commit b131719

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/create-aggregate
# Conflicts: # src/ast/ddl.rs # src/ast/mod.rs
2 parents aff2e81 + bf190c0 commit b131719

6 files changed

Lines changed: 344 additions & 2 deletions

File tree

src/ast/ddl.rs

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5910,3 +5910,127 @@ impl fmt::Display for AggregateModifyKind {
59105910
}
59115911
}
59125912
}
5913+
5914+
/// `CREATE TEXT SEARCH CONFIGURATION` statement.
5915+
///
5916+
/// Note: this is a PostgreSQL-specific statement.
5917+
/// <https://www.postgresql.org/docs/current/sql-createtsconfig.html>
5918+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5919+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5920+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5921+
pub struct CreateTextSearchConfiguration {
5922+
/// Name of the text search configuration being created.
5923+
pub name: ObjectName,
5924+
/// Options list — must include `PARSER = parser_name`.
5925+
pub options: Vec<SqlOption>,
5926+
}
5927+
5928+
impl fmt::Display for CreateTextSearchConfiguration {
5929+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5930+
write!(
5931+
f,
5932+
"CREATE TEXT SEARCH CONFIGURATION {name} ({options})",
5933+
name = self.name,
5934+
options = display_comma_separated(&self.options),
5935+
)
5936+
}
5937+
}
5938+
5939+
impl From<CreateTextSearchConfiguration> for crate::ast::Statement {
5940+
fn from(v: CreateTextSearchConfiguration) -> Self {
5941+
crate::ast::Statement::CreateTextSearchConfiguration(v)
5942+
}
5943+
}
5944+
5945+
/// `CREATE TEXT SEARCH DICTIONARY` statement.
5946+
///
5947+
/// Note: this is a PostgreSQL-specific statement.
5948+
/// <https://www.postgresql.org/docs/current/sql-createtsdictionary.html>
5949+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5950+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5951+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5952+
pub struct CreateTextSearchDictionary {
5953+
/// Name of the text search dictionary being created.
5954+
pub name: ObjectName,
5955+
/// Options list — must include `TEMPLATE = template_name`.
5956+
pub options: Vec<SqlOption>,
5957+
}
5958+
5959+
impl fmt::Display for CreateTextSearchDictionary {
5960+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5961+
write!(
5962+
f,
5963+
"CREATE TEXT SEARCH DICTIONARY {name} ({options})",
5964+
name = self.name,
5965+
options = display_comma_separated(&self.options),
5966+
)
5967+
}
5968+
}
5969+
5970+
impl From<CreateTextSearchDictionary> for crate::ast::Statement {
5971+
fn from(v: CreateTextSearchDictionary) -> Self {
5972+
crate::ast::Statement::CreateTextSearchDictionary(v)
5973+
}
5974+
}
5975+
5976+
/// `CREATE TEXT SEARCH PARSER` statement.
5977+
///
5978+
/// Note: this is a PostgreSQL-specific statement.
5979+
/// <https://www.postgresql.org/docs/current/sql-createtsparser.html>
5980+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5981+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5982+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5983+
pub struct CreateTextSearchParser {
5984+
/// Name of the text search parser being created.
5985+
pub name: ObjectName,
5986+
/// Options list — must include `START`, `GETTOKEN`, `END`, `LEXTYPES` (and optionally `HEADLINE`).
5987+
pub options: Vec<SqlOption>,
5988+
}
5989+
5990+
impl fmt::Display for CreateTextSearchParser {
5991+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5992+
write!(
5993+
f,
5994+
"CREATE TEXT SEARCH PARSER {name} ({options})",
5995+
name = self.name,
5996+
options = display_comma_separated(&self.options),
5997+
)
5998+
}
5999+
}
6000+
6001+
impl From<CreateTextSearchParser> for crate::ast::Statement {
6002+
fn from(v: CreateTextSearchParser) -> Self {
6003+
crate::ast::Statement::CreateTextSearchParser(v)
6004+
}
6005+
}
6006+
6007+
/// `CREATE TEXT SEARCH TEMPLATE` statement.
6008+
///
6009+
/// Note: this is a PostgreSQL-specific statement.
6010+
/// <https://www.postgresql.org/docs/current/sql-createtstemplate.html>
6011+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6012+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6013+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6014+
pub struct CreateTextSearchTemplate {
6015+
/// Name of the text search template being created.
6016+
pub name: ObjectName,
6017+
/// Options list — must include `LEXIZE` (and optionally `INIT`).
6018+
pub options: Vec<SqlOption>,
6019+
}
6020+
6021+
impl fmt::Display for CreateTextSearchTemplate {
6022+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6023+
write!(
6024+
f,
6025+
"CREATE TEXT SEARCH TEMPLATE {name} ({options})",
6026+
name = self.name,
6027+
options = display_comma_separated(&self.options),
6028+
)
6029+
}
6030+
}
6031+
6032+
impl From<CreateTextSearchTemplate> for crate::ast::Statement {
6033+
fn from(v: CreateTextSearchTemplate) -> Self {
6034+
crate::ast::Statement::CreateTextSearchTemplate(v)
6035+
}
6036+
}

src/ast/mod.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ pub use self::ddl::{
7171
ColumnPolicy, ColumnPolicyProperty, ConstraintCharacteristics, CreateAggregate,
7272
CreateAggregateOption, CreateCollation, CreateCollationDefinition, CreateConnector,
7373
CreateDomain, CreateExtension, CreateFunction, CreateIndex, CreateOperator, CreateOperatorClass,
74-
CreateOperatorFamily, CreatePolicy, CreatePolicyCommand, CreatePolicyType,
75-
CreateTable, CreateTrigger, CreateView, Deduplicate, DeferrableInitial, DistStyle,
74+
CreateOperatorFamily, CreatePolicy, CreatePolicyCommand, CreatePolicyType, CreateTable,
75+
CreateTextSearchConfiguration, CreateTextSearchDictionary, CreateTextSearchParser,
76+
CreateTextSearchTemplate, CreateTrigger, CreateView, Deduplicate, DeferrableInitial, DistStyle,
7677
DropBehavior, DropExtension, DropFunction, DropOperator, DropOperatorClass, DropOperatorFamily,
7778
DropOperatorSignature, DropPolicy, DropTrigger, ForValues, FunctionReturnType, GeneratedAs,
7879
GeneratedExpressionMode, IdentityParameters, IdentityProperty, IdentityPropertyFormatKind,
@@ -3981,6 +3982,30 @@ pub enum Statement {
39813982
/// <https://www.postgresql.org/docs/current/sql-createcollation.html>
39823983
CreateCollation(CreateCollation),
39833984
/// ```sql
3985+
/// CREATE TEXT SEARCH CONFIGURATION name ( PARSER = parser_name )
3986+
/// ```
3987+
/// Note: this is a PostgreSQL-specific statement.
3988+
/// <https://www.postgresql.org/docs/current/sql-createtsconfig.html>
3989+
CreateTextSearchConfiguration(CreateTextSearchConfiguration),
3990+
/// ```sql
3991+
/// CREATE TEXT SEARCH DICTIONARY name ( TEMPLATE = template_name [, option = value, ...] )
3992+
/// ```
3993+
/// Note: this is a PostgreSQL-specific statement.
3994+
/// <https://www.postgresql.org/docs/current/sql-createtsdictionary.html>
3995+
CreateTextSearchDictionary(CreateTextSearchDictionary),
3996+
/// ```sql
3997+
/// CREATE TEXT SEARCH PARSER name ( START = start_fn, GETTOKEN = gettoken_fn, END = end_fn, LEXTYPES = lextypes_fn [, HEADLINE = headline_fn] )
3998+
/// ```
3999+
/// Note: this is a PostgreSQL-specific statement.
4000+
/// <https://www.postgresql.org/docs/current/sql-createtsparser.html>
4001+
CreateTextSearchParser(CreateTextSearchParser),
4002+
/// ```sql
4003+
/// CREATE TEXT SEARCH TEMPLATE name ( [INIT = init_fn,] LEXIZE = lexize_fn )
4004+
/// ```
4005+
/// Note: this is a PostgreSQL-specific statement.
4006+
/// <https://www.postgresql.org/docs/current/sql-createtstemplate.html>
4007+
CreateTextSearchTemplate(CreateTextSearchTemplate),
4008+
/// ```sql
39844009
/// DROP EXTENSION [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]
39854010
/// ```
39864011
/// Note: this is a PostgreSQL-specific statement.
@@ -5463,6 +5488,10 @@ impl fmt::Display for Statement {
54635488
Statement::CreateIndex(create_index) => create_index.fmt(f),
54645489
Statement::CreateExtension(create_extension) => write!(f, "{create_extension}"),
54655490
Statement::CreateCollation(create_collation) => write!(f, "{create_collation}"),
5491+
Statement::CreateTextSearchConfiguration(v) => write!(f, "{v}"),
5492+
Statement::CreateTextSearchDictionary(v) => write!(f, "{v}"),
5493+
Statement::CreateTextSearchParser(v) => write!(f, "{v}"),
5494+
Statement::CreateTextSearchTemplate(v) => write!(f, "{v}"),
54665495
Statement::DropExtension(drop_extension) => write!(f, "{drop_extension}"),
54675496
Statement::DropOperator(drop_operator) => write!(f, "{drop_operator}"),
54685497
Statement::DropOperatorFamily(drop_operator_family) => {

src/ast/spans.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ impl Spanned for Values {
265265
/// - [Statement::Declare]
266266
/// - [Statement::CreateExtension]
267267
/// - [Statement::CreateCollation]
268+
/// - [Statement::CreateTextSearchConfiguration]
269+
/// - [Statement::CreateTextSearchDictionary]
270+
/// - [Statement::CreateTextSearchParser]
271+
/// - [Statement::CreateTextSearchTemplate]
268272
/// - [Statement::AlterCollation]
269273
/// - [Statement::Fetch]
270274
/// - [Statement::Flush]
@@ -380,6 +384,10 @@ impl Spanned for Statement {
380384
Statement::CreateRole(create_role) => create_role.span(),
381385
Statement::CreateExtension(create_extension) => create_extension.span(),
382386
Statement::CreateCollation(create_collation) => create_collation.span(),
387+
Statement::CreateTextSearchConfiguration(_) => Span::empty(),
388+
Statement::CreateTextSearchDictionary(_) => Span::empty(),
389+
Statement::CreateTextSearchParser(_) => Span::empty(),
390+
Statement::CreateTextSearchTemplate(_) => Span::empty(),
383391
Statement::DropExtension(drop_extension) => drop_extension.span(),
384392
Statement::DropOperator(drop_operator) => drop_operator.span(),
385393
Statement::DropOperatorFamily(drop_operator_family) => drop_operator_family.span(),

src/keywords.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ define_keywords!(
244244
COMPRESSION,
245245
COMPUPDATE,
246246
COMPUTE,
247+
CONFIGURATION,
247248
CONCURRENTLY,
248249
CONDITION,
249250
CONFLICT,
@@ -333,6 +334,7 @@ define_keywords!(
333334
DETACH,
334335
DETAIL,
335336
DETERMINISTIC,
337+
DICTIONARY,
336338
DIMENSIONS,
337339
DIRECTORY,
338340
DISABLE,
@@ -765,6 +767,7 @@ define_keywords!(
765767
PARALLEL,
766768
PARAMETER,
767769
PARQUET,
770+
PARSER,
768771
PART,
769772
PARTIAL,
770773
PARTITION,
@@ -1035,6 +1038,7 @@ define_keywords!(
10351038
TASK,
10361039
TBLPROPERTIES,
10371040
TEMP,
1041+
TEMPLATE,
10381042
TEMPORARY,
10391043
TEMPTABLE,
10401044
TERMINATED,

src/parser/mod.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5215,6 +5215,8 @@ impl<'a> Parser<'a> {
52155215
}
52165216
} else if self.parse_keyword(Keyword::SERVER) {
52175217
self.parse_pg_create_server()
5218+
} else if self.parse_keywords(&[Keyword::TEXT, Keyword::SEARCH]) {
5219+
self.parse_create_text_search()
52185220
} else {
52195221
self.expected_ref("an object type after CREATE", self.peek_token_ref())
52205222
}
@@ -8367,6 +8369,49 @@ impl<'a> Parser<'a> {
83678369
})
83688370
}
83698371

8372+
/// Parse a PostgreSQL-specific `CREATE TEXT SEARCH CONFIGURATION | DICTIONARY | PARSER | TEMPLATE` statement.
8373+
pub fn parse_create_text_search(&mut self) -> Result<Statement, ParserError> {
8374+
if self.parse_keyword(Keyword::CONFIGURATION) {
8375+
let name = self.parse_object_name(false)?;
8376+
self.expect_token(&Token::LParen)?;
8377+
let options = self.parse_comma_separated(Parser::parse_sql_option)?;
8378+
self.expect_token(&Token::RParen)?;
8379+
Ok(Statement::CreateTextSearchConfiguration(
8380+
CreateTextSearchConfiguration { name, options },
8381+
))
8382+
} else if self.parse_keyword(Keyword::DICTIONARY) {
8383+
let name = self.parse_object_name(false)?;
8384+
self.expect_token(&Token::LParen)?;
8385+
let options = self.parse_comma_separated(Parser::parse_sql_option)?;
8386+
self.expect_token(&Token::RParen)?;
8387+
Ok(Statement::CreateTextSearchDictionary(
8388+
CreateTextSearchDictionary { name, options },
8389+
))
8390+
} else if self.parse_keyword(Keyword::PARSER) {
8391+
let name = self.parse_object_name(false)?;
8392+
self.expect_token(&Token::LParen)?;
8393+
let options = self.parse_comma_separated(Parser::parse_sql_option)?;
8394+
self.expect_token(&Token::RParen)?;
8395+
Ok(Statement::CreateTextSearchParser(CreateTextSearchParser {
8396+
name,
8397+
options,
8398+
}))
8399+
} else if self.parse_keyword(Keyword::TEMPLATE) {
8400+
let name = self.parse_object_name(false)?;
8401+
self.expect_token(&Token::LParen)?;
8402+
let options = self.parse_comma_separated(Parser::parse_sql_option)?;
8403+
self.expect_token(&Token::RParen)?;
8404+
Ok(Statement::CreateTextSearchTemplate(
8405+
CreateTextSearchTemplate { name, options },
8406+
))
8407+
} else {
8408+
self.expected_ref(
8409+
"CONFIGURATION, DICTIONARY, PARSER, or TEMPLATE after CREATE TEXT SEARCH",
8410+
self.peek_token_ref(),
8411+
)
8412+
}
8413+
}
8414+
83708415
/// Parse a PostgreSQL-specific [Statement::DropExtension] statement.
83718416
pub fn parse_drop_extension(&mut self) -> Result<Statement, ParserError> {
83728417
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);

0 commit comments

Comments
 (0)