Skip to content

Commit feeb32a

Browse files
authored
Add alternative syntax for extract, trim and substring. (#13143)
1 parent 80ad713 commit feeb32a

File tree

6 files changed

+40
-0
lines changed

6 files changed

+40
-0
lines changed

datafusion/functions/src/datetime/date_part.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ fn get_date_part_doc() -> &'static Documentation {
255255
"expression",
256256
"Time expression to operate on. Can be a constant, column, or function.",
257257
)
258+
.with_alternative_syntax("extract(field FROM source)")
258259
.build()
259260
.unwrap()
260261
})

datafusion/functions/src/string/btrim.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ fn get_btrim_doc() -> &'static Documentation {
124124
```"#)
125125
.with_standard_argument("str", Some("String"))
126126
.with_argument("trim_str", "String expression to operate on. Can be a constant, column, or function, and any combination of operators. _Default is whitespace characters._")
127+
.with_alternative_syntax("trim(BOTH trim_str FROM str)")
128+
.with_alternative_syntax("trim(trim_str FROM str)")
127129
.with_related_udf("ltrim")
128130
.with_related_udf("rtrim")
129131
.build()

datafusion/functions/src/string/ltrim.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ fn get_ltrim_doc() -> &'static Documentation {
124124
```"#)
125125
.with_standard_argument("str", Some("String"))
126126
.with_argument("trim_str", "String expression to trim from the beginning of the input string. Can be a constant, column, or function, and any combination of arithmetic operators. _Default is whitespace characters._")
127+
.with_alternative_syntax("trim(LEADING trim_str FROM str)")
127128
.with_related_udf("btrim")
128129
.with_related_udf("rtrim")
129130
.build()

datafusion/functions/src/string/rtrim.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ fn get_rtrim_doc() -> &'static Documentation {
124124
```"#)
125125
.with_standard_argument("str", Some("String"))
126126
.with_argument("trim_str", "String expression to trim from the end of the input string. Can be a constant, column, or function, and any combination of arithmetic operators. _Default is whitespace characters._")
127+
.with_alternative_syntax("trim(TRAILING trim_str FROM str)")
127128
.with_related_udf("btrim")
128129
.with_related_udf("ltrim")
129130
.build()

datafusion/functions/src/unicode/substr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ fn get_substr_doc() -> &'static Documentation {
173173
.with_standard_argument("str", Some("String"))
174174
.with_argument("start_pos", "Character position to start the substring at. The first character in the string has a position of 1.")
175175
.with_argument("length", "Number of characters to extract. If not specified, returns the rest of the string after the start position.")
176+
.with_alternative_syntax("substring(str from start_pos for length)")
176177
.build()
177178
.unwrap()
178179
})

docs/source/user-guide/sql/scalar_functions_new.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,16 @@ btrim(str[, trim_str])
808808
+-------------------------------------------+
809809
```
810810

811+
#### Alternative Syntax
812+
813+
```sql
814+
trim(BOTH trim_str FROM str)
815+
```
816+
817+
```sql
818+
trim(trim_str FROM str)
819+
```
820+
811821
#### Aliases
812822

813823
- trim
@@ -1191,6 +1201,12 @@ ltrim(str[, trim_str])
11911201
+-------------------------------------------+
11921202
```
11931203

1204+
#### Alternative Syntax
1205+
1206+
```sql
1207+
trim(LEADING trim_str FROM str)
1208+
```
1209+
11941210
**Related functions**:
11951211

11961212
- [btrim](#btrim)
@@ -1387,6 +1403,12 @@ rtrim(str[, trim_str])
13871403
+-------------------------------------------+
13881404
```
13891405

1406+
#### Alternative Syntax
1407+
1408+
```sql
1409+
trim(TRAILING trim_str FROM str)
1410+
```
1411+
13901412
**Related functions**:
13911413

13921414
- [btrim](#btrim)
@@ -1501,6 +1523,12 @@ substr(str, start_pos[, length])
15011523
+----------------------------------------------+
15021524
```
15031525

1526+
#### Alternative Syntax
1527+
1528+
```sql
1529+
substring(str from start_pos for length)
1530+
```
1531+
15041532
#### Aliases
15051533

15061534
- substring
@@ -1965,6 +1993,12 @@ date_part(part, expression)
19651993

19661994
- **expression**: Time expression to operate on. Can be a constant, column, or function.
19671995

1996+
#### Alternative Syntax
1997+
1998+
```sql
1999+
extract(field FROM source)
2000+
```
2001+
19682002
#### Aliases
19692003

19702004
- datepart

0 commit comments

Comments
 (0)