You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by if...@apache.org on 2025/06/22 07:02:56 UTC
(datafusion-sqlparser-rs) branch main updated: Postgres: Add support for text search types (#1889)
This is an automated email from the ASF dual-hosted git repository.
iffyio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 1d0dc7cd Postgres: Add support for text search types (#1889)
1d0dc7cd is described below
commit 1d0dc7cdd8209d5e68f41675622dd17e2b336e26
Author: Mohamed Abdeen <83...@users.noreply.github.com>
AuthorDate: Sun Jun 22 08:02:51 2025 +0100
Postgres: Add support for text search types (#1889)
---
src/ast/data_type.rs | 10 ++++++++++
src/keywords.rs | 2 ++
src/parser/mod.rs | 6 ++++++
tests/sqlparser_postgres.rs | 31 +++++++++++++++++++++++++++++++
4 files changed, 49 insertions(+)
diff --git a/src/ast/data_type.rs b/src/ast/data_type.rs
index 3a4958c9..ef04b7e4 100644
--- a/src/ast/data_type.rs
+++ b/src/ast/data_type.rs
@@ -446,6 +446,14 @@ pub enum DataType {
///
/// [PostgreSQL]: https://www.postgresql.org/docs/9.5/functions-geometry.html
GeometricType(GeometricTypeKind),
+ /// PostgreSQL text search vectors, see [PostgreSQL].
+ ///
+ /// [PostgreSQL]: https://www.postgresql.org/docs/17/datatype-textsearch.html
+ TsVector,
+ /// PostgreSQL text search query, see [PostgreSQL].
+ ///
+ /// [PostgreSQL]: https://www.postgresql.org/docs/17/datatype-textsearch.html
+ TsQuery,
}
impl fmt::Display for DataType {
@@ -738,6 +746,8 @@ impl fmt::Display for DataType {
write!(f, "{} TABLE ({})", name, display_comma_separated(columns))
}
DataType::GeometricType(kind) => write!(f, "{}", kind),
+ DataType::TsVector => write!(f, "TSVECTOR"),
+ DataType::TsQuery => write!(f, "TSQUERY"),
}
}
}
diff --git a/src/keywords.rs b/src/keywords.rs
index cb6c7a6e..f56178c1 100644
--- a/src/keywords.rs
+++ b/src/keywords.rs
@@ -935,6 +935,8 @@ define_keywords!(
TRY,
TRY_CAST,
TRY_CONVERT,
+ TSQUERY,
+ TSVECTOR,
TUPLE,
TYPE,
UBIGINT,
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index be32093f..f60323b2 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -9909,6 +9909,12 @@ impl<'a> Parser<'a> {
Ok(DataType::Unsigned)
}
}
+ Keyword::TSVECTOR if dialect_is!(dialect is PostgreSqlDialect | GenericDialect) => {
+ Ok(DataType::TsVector)
+ }
+ Keyword::TSQUERY if dialect_is!(dialect is PostgreSqlDialect | GenericDialect) => {
+ Ok(DataType::TsQuery)
+ }
_ => {
self.prev_token();
let type_name = self.parse_object_name(false)?;
diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs
index 6f0ba9c6..b6605cf1 100644
--- a/tests/sqlparser_postgres.rs
+++ b/tests/sqlparser_postgres.rs
@@ -6201,3 +6201,34 @@ fn parse_alter_table_replica_identity() {
_ => unreachable!(),
}
}
+
+#[test]
+fn parse_ts_datatypes() {
+ match pg_and_generic().verified_stmt("CREATE TABLE foo (x TSVECTOR)") {
+ Statement::CreateTable(CreateTable { columns, .. }) => {
+ assert_eq!(
+ columns,
+ vec![ColumnDef {
+ name: "x".into(),
+ data_type: DataType::TsVector,
+ options: vec![],
+ }]
+ );
+ }
+ _ => unreachable!(),
+ }
+
+ match pg_and_generic().verified_stmt("CREATE TABLE foo (x TSQUERY)") {
+ Statement::CreateTable(CreateTable { columns, .. }) => {
+ assert_eq!(
+ columns,
+ vec![ColumnDef {
+ name: "x".into(),
+ data_type: DataType::TsQuery,
+ options: vec![],
+ }]
+ );
+ }
+ _ => unreachable!(),
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org