-2

I want to split a string in CRATE. I tried with substr, but it takes only substr(string,long,long). I want something like a function which can take delimiter string.

Example :

value=1234-5656

select SUBSTR(value, '-',1) as first from XYZ;

I want to split the value into 1234 and 5656 in a SQL query. But CRATE does not support SUBSTR(value, '-',1). So I am looking for an option to split the value in the CRATE query.

Any help?

goosebump
  • 96
  • 1
  • 2
  • 13

3 Answers3

0

SUBSTRING_INDEX comes in handy here:

SELECT
    SUBSTRING_INDEX('1234-5656', '-', 1)  AS first,
    SUBSTRING_INDEX('1234-5656', '-', -1) AS second
FROM yourTable;

enter image description here

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

please try using this query:

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(name, '_', 1), '_', -1) as beforesplit, SUBSTRING_INDEX(SUBSTRING_INDEX(name, '_', 2), '_', -1) as aftersplit FROM testenter
0

For CrateDB you probably want to use regex_matches function more info on Create's documentation site

However the following should give you what you're looking for

select regexp_matches(yourColumnName, '([0-9])\w+')[1] from yourTable 
metase
  • 1,169
  • 2
  • 16
  • 29