mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 15:04:04 +00:00
Parse casting to array using double colon operator in Redshift (#1737)
This commit is contained in:
parent
1f1c0693da
commit
7fc37a76e5
7 changed files with 21 additions and 8 deletions
|
@ -82,7 +82,7 @@ impl Dialect for DuckDbDialect {
|
||||||
}
|
}
|
||||||
|
|
||||||
// See DuckDB <https://duckdb.org/docs/sql/data_types/array.html#defining-an-array-field>
|
// See DuckDB <https://duckdb.org/docs/sql/data_types/array.html#defining-an-array-field>
|
||||||
fn supports_array_typedef_size(&self) -> bool {
|
fn supports_array_typedef_with_brackets(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@ impl Dialect for GenericDialect {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn supports_array_typedef_size(&self) -> bool {
|
fn supports_array_typedef_with_brackets(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -931,9 +931,11 @@ pub trait Dialect: Debug + Any {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the dialect supports size definition for array types.
|
/// Returns true if the dialect supports array type definition with brackets with
|
||||||
/// For example: ```CREATE TABLE my_table (my_array INT[3])```.
|
/// an optional size. For example:
|
||||||
fn supports_array_typedef_size(&self) -> bool {
|
/// ```CREATE TABLE my_table (arr1 INT[], arr2 INT[3])```
|
||||||
|
/// ```SELECT x::INT[]```
|
||||||
|
fn supports_array_typedef_with_brackets(&self) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
/// Returns true if the dialect supports geometric types.
|
/// Returns true if the dialect supports geometric types.
|
||||||
|
|
|
@ -247,7 +247,7 @@ impl Dialect for PostgreSqlDialect {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// See: <https://www.postgresql.org/docs/current/arrays.html#ARRAYS-DECLARATION>
|
/// See: <https://www.postgresql.org/docs/current/arrays.html#ARRAYS-DECLARATION>
|
||||||
fn supports_array_typedef_size(&self) -> bool {
|
fn supports_array_typedef_with_brackets(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,4 +117,8 @@ impl Dialect for RedshiftSqlDialect {
|
||||||
fn supports_geometric_types(&self) -> bool {
|
fn supports_geometric_types(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn supports_array_typedef_with_brackets(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9123,9 +9123,9 @@ impl<'a> Parser<'a> {
|
||||||
_ => self.expected_at("a data type name", next_token_index),
|
_ => self.expected_at("a data type name", next_token_index),
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
if self.dialect.supports_array_typedef_size() {
|
if self.dialect.supports_array_typedef_with_brackets() {
|
||||||
// Parse array data type size
|
|
||||||
while self.consume_token(&Token::LBracket) {
|
while self.consume_token(&Token::LBracket) {
|
||||||
|
// Parse optional array data type size
|
||||||
let size = self.maybe_parse(|p| p.parse_literal_uint())?;
|
let size = self.maybe_parse(|p| p.parse_literal_uint())?;
|
||||||
self.expect_token(&Token::RBracket)?;
|
self.expect_token(&Token::RBracket)?;
|
||||||
data = DataType::Array(ArrayElemTypeDef::SquareBracket(Box::new(data), size))
|
data = DataType::Array(ArrayElemTypeDef::SquareBracket(Box::new(data), size))
|
||||||
|
|
|
@ -14386,3 +14386,10 @@ fn test_geometric_binary_operators() {
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_array_type_def_with_brackets() {
|
||||||
|
let dialects = all_dialects_where(|d| d.supports_array_typedef_with_brackets());
|
||||||
|
dialects.verified_stmt("SELECT x::INT[]");
|
||||||
|
dialects.verified_stmt("SELECT STRING_TO_ARRAY('1,2,3', ',')::INT[3]");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue