Better way to split a string?


#1

I have a document element that looks like this …

“ip”: “123.12.11.4”

I need to be able to get each ‘octet’ out of that value (split it on the ‘.’) I can get the first portion with a case statement:

case
when
substr(ws.ip, 1, 1) == '.'
then
substr(ws.ip, 0, 1)
when
substr(ws.ip, 2, 1) == '.'
then
substr(ws.ip, 0, 2)
else
substr(ws.ip, 0, 3)
end
as ip1

However, after the first part I can’t reference ip1 in any other function to start getting the next part. Anyone have any ideas?


#2

Hello,

We already have SPLIT() function coming in DP4; this splits a string into an array of strings, based on a separator.

Unfortunately, in DP3, the combination of CASE and SUBSTR() seems to be the only way to do this.

If we do provide an update to DP3 that includes the SPLIT() function, we will post another reply to this post.

Sorry that this wasn’t available sooner.


#3

I saw that in the couchbaselabs/query github project. Is there currently any documentation for getting that into couchbaselabs/tuqtng for testing … or am I not looking at the right projects?


#4

I also just wanted to say thank you for the quick response and all of you work on the project.

Thank You!


#5

You are looking at the right repos. We will add SPLIT() to tuqtng and send you a pointer.

Thank you for using N1QL!


#6

JIRA ticket: http://www.couchbase.com/issues/browse/MB-10986


#7

Hello,

The N1QL DP3 download has been updated to include the SPLIT() function.

SPLIT() uses whitespace as the delimiter.

SPLIT(, ) uses the specified delimiter.


#8

Great, thank you!


#9

SPLIT(string) uses whitespace as the delimiter.

SPLIT(string, delim) uses the specified delimiter.


#10

Is there a way to split on multiple delimiters?
In my case I would like to split on both whitespace and dashes.


#11

You can do the following.

SPLIT( REPLACE( string, "-", " " ) )