Skip to content

Commit

Permalink
feat: add options to substring for start parameter being negative (#508)
Browse files Browse the repository at this point in the history
The substring function `start` parameter has different behavior between
different
backends when it's value negative. Sqlite will wrap around the end of
the input string,
whereas postgres will start from the left of the input string.
  • Loading branch information
richtia committed Jul 21, 2023
1 parent 89b0c62 commit 281dc0f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions extensions/functions_string.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ scalar_functions:
A `start` value of 1 refers to the first characters of the string. When
`length` is not specified the function will extract a substring starting
from position `start` and ending at the end of the string.
The `negative_start` option applies to the `start` parameter. `WRAP_FROM_END` means
the index will start from the end of the `input` and move backwards.
The last character has an index of -1, the second to last character has an index of -2,
and so on. `LEFT_OF_BEGINNING` means the returned substring will start from
the left of the first character. A `start` of -1 will begin 2 characters left of the
the `input`, while a `start` of 0 begins 1 character left of the `input`.
impls:
- args:
- value: "varchar<L1>"
Expand All @@ -61,6 +68,9 @@ scalar_functions:
name: "start"
- value: i32
name: "length"
options:
negative_start:
values: [ WRAP_FROM_END, LEFT_OF_BEGINNING, ERROR ]
return: "varchar<L1>"
- args:
- value: "string"
Expand All @@ -69,6 +79,9 @@ scalar_functions:
name: "start"
- value: i32
name: "length"
options:
negative_start:
values: [ WRAP_FROM_END, LEFT_OF_BEGINNING, ERROR ]
return: "string"
- args:
- value: "fixedchar<l1>"
Expand All @@ -77,24 +90,36 @@ scalar_functions:
name: "start"
- value: i32
name: "length"
options:
negative_start:
values: [ WRAP_FROM_END, LEFT_OF_BEGINNING, ERROR ]
return: "string"
- args:
- value: "varchar<L1>"
name: "input"
- value: i32
name: "start"
options:
negative_start:
values: [ WRAP_FROM_END, LEFT_OF_BEGINNING ]
return: "varchar<L1>"
- args:
- value: "string"
name: "input"
- value: i32
name: "start"
options:
negative_start:
values: [ WRAP_FROM_END, LEFT_OF_BEGINNING ]
return: "string"
- args:
- value: "fixedchar<l1>"
name: "input"
- value: i32
name: "start"
options:
negative_start:
values: [ WRAP_FROM_END, LEFT_OF_BEGINNING ]
return: "string"
-
name: regexp_match_substring
Expand Down

0 comments on commit 281dc0f

Please sign in to comment.