From 281dc0fba176df22fc35ff5f5acb7a05863b9d59 Mon Sep 17 00:00:00 2001 From: Richard Tia Date: Fri, 21 Jul 2023 08:59:07 -0700 Subject: [PATCH] feat: add options to substring for start parameter being negative (#508) 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. --- extensions/functions_string.yaml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/extensions/functions_string.yaml b/extensions/functions_string.yaml index 7842e94eb..159988c47 100644 --- a/extensions/functions_string.yaml +++ b/extensions/functions_string.yaml @@ -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" @@ -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" - args: - value: "string" @@ -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" @@ -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" name: "input" - value: i32 name: "start" + options: + negative_start: + values: [ WRAP_FROM_END, LEFT_OF_BEGINNING ] return: "varchar" - args: - value: "string" name: "input" - value: i32 name: "start" + options: + negative_start: + values: [ WRAP_FROM_END, LEFT_OF_BEGINNING ] return: "string" - args: - value: "fixedchar" name: "input" - value: i32 name: "start" + options: + negative_start: + values: [ WRAP_FROM_END, LEFT_OF_BEGINNING ] return: "string" - name: regexp_match_substring