Skip to content

Commit 287f90f

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/foreign-table-fdw
# Conflicts: # src/ast/ddl.rs # src/ast/mod.rs # src/parser/mod.rs
2 parents ef2ce41 + bf190c0 commit 287f90f

6 files changed

Lines changed: 345 additions & 4 deletions

File tree

src/ast/ddl.rs

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5859,3 +5859,126 @@ impl From<CreateForeignTable> for crate::ast::Statement {
58595859
crate::ast::Statement::CreateForeignTable(v)
58605860
}
58615861
}
5862+
/// `CREATE TEXT SEARCH CONFIGURATION` statement.
5863+
///
5864+
/// Note: this is a PostgreSQL-specific statement.
5865+
/// <https://www.postgresql.org/docs/current/sql-createtsconfig.html>
5866+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5867+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5868+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5869+
pub struct CreateTextSearchConfiguration {
5870+
/// Name of the text search configuration being created.
5871+
pub name: ObjectName,
5872+
/// Options list — must include `PARSER = parser_name`.
5873+
pub options: Vec<SqlOption>,
5874+
}
5875+
5876+
impl fmt::Display for CreateTextSearchConfiguration {
5877+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5878+
write!(
5879+
f,
5880+
"CREATE TEXT SEARCH CONFIGURATION {name} ({options})",
5881+
name = self.name,
5882+
options = display_comma_separated(&self.options),
5883+
)
5884+
}
5885+
}
5886+
5887+
impl From<CreateTextSearchConfiguration> for crate::ast::Statement {
5888+
fn from(v: CreateTextSearchConfiguration) -> Self {
5889+
crate::ast::Statement::CreateTextSearchConfiguration(v)
5890+
}
5891+
}
5892+
5893+
/// `CREATE TEXT SEARCH DICTIONARY` statement.
5894+
///
5895+
/// Note: this is a PostgreSQL-specific statement.
5896+
/// <https://www.postgresql.org/docs/current/sql-createtsdictionary.html>
5897+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5898+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5899+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5900+
pub struct CreateTextSearchDictionary {
5901+
/// Name of the text search dictionary being created.
5902+
pub name: ObjectName,
5903+
/// Options list — must include `TEMPLATE = template_name`.
5904+
pub options: Vec<SqlOption>,
5905+
}
5906+
5907+
impl fmt::Display for CreateTextSearchDictionary {
5908+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5909+
write!(
5910+
f,
5911+
"CREATE TEXT SEARCH DICTIONARY {name} ({options})",
5912+
name = self.name,
5913+
options = display_comma_separated(&self.options),
5914+
)
5915+
}
5916+
}
5917+
5918+
impl From<CreateTextSearchDictionary> for crate::ast::Statement {
5919+
fn from(v: CreateTextSearchDictionary) -> Self {
5920+
crate::ast::Statement::CreateTextSearchDictionary(v)
5921+
}
5922+
}
5923+
5924+
/// `CREATE TEXT SEARCH PARSER` statement.
5925+
///
5926+
/// Note: this is a PostgreSQL-specific statement.
5927+
/// <https://www.postgresql.org/docs/current/sql-createtsparser.html>
5928+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5929+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5930+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5931+
pub struct CreateTextSearchParser {
5932+
/// Name of the text search parser being created.
5933+
pub name: ObjectName,
5934+
/// Options list — must include `START`, `GETTOKEN`, `END`, `LEXTYPES` (and optionally `HEADLINE`).
5935+
pub options: Vec<SqlOption>,
5936+
}
5937+
5938+
impl fmt::Display for CreateTextSearchParser {
5939+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5940+
write!(
5941+
f,
5942+
"CREATE TEXT SEARCH PARSER {name} ({options})",
5943+
name = self.name,
5944+
options = display_comma_separated(&self.options),
5945+
)
5946+
}
5947+
}
5948+
5949+
impl From<CreateTextSearchParser> for crate::ast::Statement {
5950+
fn from(v: CreateTextSearchParser) -> Self {
5951+
crate::ast::Statement::CreateTextSearchParser(v)
5952+
}
5953+
}
5954+
5955+
/// `CREATE TEXT SEARCH TEMPLATE` statement.
5956+
///
5957+
/// Note: this is a PostgreSQL-specific statement.
5958+
/// <https://www.postgresql.org/docs/current/sql-createtstemplate.html>
5959+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5960+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5961+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5962+
pub struct CreateTextSearchTemplate {
5963+
/// Name of the text search template being created.
5964+
pub name: ObjectName,
5965+
/// Options list — must include `LEXIZE` (and optionally `INIT`).
5966+
pub options: Vec<SqlOption>,
5967+
}
5968+
5969+
impl fmt::Display for CreateTextSearchTemplate {
5970+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5971+
write!(
5972+
f,
5973+
"CREATE TEXT SEARCH TEMPLATE {name} ({options})",
5974+
name = self.name,
5975+
options = display_comma_separated(&self.options),
5976+
)
5977+
}
5978+
}
5979+
5980+
impl From<CreateTextSearchTemplate> for crate::ast::Statement {
5981+
fn from(v: CreateTextSearchTemplate) -> Self {
5982+
crate::ast::Statement::CreateTextSearchTemplate(v)
5983+
}
5984+
}

src/ast/mod.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ pub use self::ddl::{
7171
ColumnPolicyProperty, ConstraintCharacteristics, CreateCollation, CreateCollationDefinition,
7272
CreateConnector, CreateDomain, CreateExtension, CreateForeignDataWrapper, CreateForeignTable,
7373
CreateFunction, CreateIndex, CreateOperator, CreateOperatorClass, CreateOperatorFamily,
74-
CreatePolicy, CreatePolicyCommand, CreatePolicyType, CreateTable, CreateTrigger, CreateView,
75-
Deduplicate, DeferrableInitial, DistStyle, DropBehavior, DropExtension, DropFunction,
76-
DropOperator, DropOperatorClass, DropOperatorFamily, DropOperatorSignature, DropPolicy,
77-
DropTrigger, FdwRoutineClause, ForValues, FunctionReturnType, GeneratedAs,
74+
CreatePolicy, CreatePolicyCommand, CreatePolicyType, CreateTable, CreateTextSearchConfiguration,
75+
CreateTextSearchDictionary, CreateTextSearchParser, CreateTextSearchTemplate, CreateTrigger,
76+
CreateView, Deduplicate, DeferrableInitial, DistStyle, DropBehavior, DropExtension,
77+
DropFunction, DropOperator, DropOperatorClass, DropOperatorFamily, DropOperatorSignature,
78+
DropPolicy, DropTrigger, FdwRoutineClause, ForValues, FunctionReturnType, GeneratedAs,
7879
GeneratedExpressionMode, IdentityParameters, IdentityProperty, IdentityPropertyFormatKind,
7980
IdentityPropertyKind, IdentityPropertyOrder, IndexColumn, IndexOption, IndexType,
8081
KeyOrIndexDisplay, Msck, NullsDistinctOption, OperatorArgTypes, OperatorClassItem,
@@ -3986,6 +3987,30 @@ pub enum Statement {
39863987
/// <https://www.postgresql.org/docs/current/sql-createcollation.html>
39873988
CreateCollation(CreateCollation),
39883989
/// ```sql
3990+
/// CREATE TEXT SEARCH CONFIGURATION name ( PARSER = parser_name )
3991+
/// ```
3992+
/// Note: this is a PostgreSQL-specific statement.
3993+
/// <https://www.postgresql.org/docs/current/sql-createtsconfig.html>
3994+
CreateTextSearchConfiguration(CreateTextSearchConfiguration),
3995+
/// ```sql
3996+
/// CREATE TEXT SEARCH DICTIONARY name ( TEMPLATE = template_name [, option = value, ...] )
3997+
/// ```
3998+
/// Note: this is a PostgreSQL-specific statement.
3999+
/// <https://www.postgresql.org/docs/current/sql-createtsdictionary.html>
4000+
CreateTextSearchDictionary(CreateTextSearchDictionary),
4001+
/// ```sql
4002+
/// CREATE TEXT SEARCH PARSER name ( START = start_fn, GETTOKEN = gettoken_fn, END = end_fn, LEXTYPES = lextypes_fn [, HEADLINE = headline_fn] )
4003+
/// ```
4004+
/// Note: this is a PostgreSQL-specific statement.
4005+
/// <https://www.postgresql.org/docs/current/sql-createtsparser.html>
4006+
CreateTextSearchParser(CreateTextSearchParser),
4007+
/// ```sql
4008+
/// CREATE TEXT SEARCH TEMPLATE name ( [INIT = init_fn,] LEXIZE = lexize_fn )
4009+
/// ```
4010+
/// Note: this is a PostgreSQL-specific statement.
4011+
/// <https://www.postgresql.org/docs/current/sql-createtstemplate.html>
4012+
CreateTextSearchTemplate(CreateTextSearchTemplate),
4013+
/// ```sql
39894014
/// DROP EXTENSION [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]
39904015
/// ```
39914016
/// Note: this is a PostgreSQL-specific statement.
@@ -5468,6 +5493,10 @@ impl fmt::Display for Statement {
54685493
Statement::CreateIndex(create_index) => create_index.fmt(f),
54695494
Statement::CreateExtension(create_extension) => write!(f, "{create_extension}"),
54705495
Statement::CreateCollation(create_collation) => write!(f, "{create_collation}"),
5496+
Statement::CreateTextSearchConfiguration(v) => write!(f, "{v}"),
5497+
Statement::CreateTextSearchDictionary(v) => write!(f, "{v}"),
5498+
Statement::CreateTextSearchParser(v) => write!(f, "{v}"),
5499+
Statement::CreateTextSearchTemplate(v) => write!(f, "{v}"),
54715500
Statement::DropExtension(drop_extension) => write!(f, "{drop_extension}"),
54725501
Statement::DropOperator(drop_operator) => write!(f, "{drop_operator}"),
54735502
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,
@@ -766,6 +768,7 @@ define_keywords!(
766768
PARALLEL,
767769
PARAMETER,
768770
PARQUET,
771+
PARSER,
769772
PART,
770773
PARTIAL,
771774
PARTITION,
@@ -1036,6 +1039,7 @@ define_keywords!(
10361039
TASK,
10371040
TBLPROPERTIES,
10381041
TEMP,
1042+
TEMPLATE,
10391043
TEMPORARY,
10401044
TEMPTABLE,
10411045
TERMINATED,

src/parser/mod.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5224,6 +5224,8 @@ impl<'a> Parser<'a> {
52245224
self.peek_token_ref(),
52255225
)
52265226
}
5227+
} else if self.parse_keywords(&[Keyword::TEXT, Keyword::SEARCH]) {
5228+
self.parse_create_text_search()
52275229
} else {
52285230
self.expected_ref("an object type after CREATE", self.peek_token_ref())
52295231
}
@@ -8188,6 +8190,49 @@ impl<'a> Parser<'a> {
81888190
})
81898191
}
81908192

8193+
/// Parse a PostgreSQL-specific `CREATE TEXT SEARCH CONFIGURATION | DICTIONARY | PARSER | TEMPLATE` statement.
8194+
pub fn parse_create_text_search(&mut self) -> Result<Statement, ParserError> {
8195+
if self.parse_keyword(Keyword::CONFIGURATION) {
8196+
let name = self.parse_object_name(false)?;
8197+
self.expect_token(&Token::LParen)?;
8198+
let options = self.parse_comma_separated(Parser::parse_sql_option)?;
8199+
self.expect_token(&Token::RParen)?;
8200+
Ok(Statement::CreateTextSearchConfiguration(
8201+
CreateTextSearchConfiguration { name, options },
8202+
))
8203+
} else if self.parse_keyword(Keyword::DICTIONARY) {
8204+
let name = self.parse_object_name(false)?;
8205+
self.expect_token(&Token::LParen)?;
8206+
let options = self.parse_comma_separated(Parser::parse_sql_option)?;
8207+
self.expect_token(&Token::RParen)?;
8208+
Ok(Statement::CreateTextSearchDictionary(
8209+
CreateTextSearchDictionary { name, options },
8210+
))
8211+
} else if self.parse_keyword(Keyword::PARSER) {
8212+
let name = self.parse_object_name(false)?;
8213+
self.expect_token(&Token::LParen)?;
8214+
let options = self.parse_comma_separated(Parser::parse_sql_option)?;
8215+
self.expect_token(&Token::RParen)?;
8216+
Ok(Statement::CreateTextSearchParser(CreateTextSearchParser {
8217+
name,
8218+
options,
8219+
}))
8220+
} else if self.parse_keyword(Keyword::TEMPLATE) {
8221+
let name = self.parse_object_name(false)?;
8222+
self.expect_token(&Token::LParen)?;
8223+
let options = self.parse_comma_separated(Parser::parse_sql_option)?;
8224+
self.expect_token(&Token::RParen)?;
8225+
Ok(Statement::CreateTextSearchTemplate(
8226+
CreateTextSearchTemplate { name, options },
8227+
))
8228+
} else {
8229+
self.expected_ref(
8230+
"CONFIGURATION, DICTIONARY, PARSER, or TEMPLATE after CREATE TEXT SEARCH",
8231+
self.peek_token_ref(),
8232+
)
8233+
}
8234+
}
8235+
81918236
/// Parse a PostgreSQL-specific [Statement::DropExtension] statement.
81928237
pub fn parse_drop_extension(&mut self) -> Result<Statement, ParserError> {
81938238
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);

0 commit comments

Comments
 (0)