I’ve worked out how to split a string into an array, but I’m not sure how I can use a trim function on each element to remove any whitespace.
Right now, when I select and separate the field, I use the following syntax (where ";" is the delimiter):
string_to_array("Column", ';') as "SplitColumn"
But if "Column" contains "something ; like ; this", the output would be
"SplitColumn":["something ", " like ", " this"]
4
Answers
You can access each elements of the array, trim them, and build back the array.
Don’t forget the inner select.
You can break the input string into an array using the
string_to_array
function and the;
delimiter. Leading and trailing whitespace will be used to generate an array with entries that contain them. Thearray_to_string
function can then be used to remove the whitespace from each entry. This function removes any excess whitespace before concatenating the array’s items into a single string. Just like in the example I am mentioningUsing the
;
delimiter, this query separates the input string into an array, cleans up each element by removing any whitespace, and then puts the array back together. You’ll get a string without any whitespace.Hope this helps 🙂
You can achieve this with the
TRIM
function along with thestring_to_array()
function;This should work:
string_to_array("Column", ‘;’) splits the "Column" into an array using ‘;’ as the delimiter. unnest turns the array into a set of rows and wrapping it in Array would convert it back to an array.