jmich738
jmich738

Reputation: 1675

RIGHT() / LEFT() functions

Is there a function in Hiveql that is equivalent to Right() or Left() function from TSQL? For example, RIGHT(col1,10) to get the first 10 characters from col1.

Upvotes: 24

Views: 86032

Answers (3)

sandeep rawat
sandeep rawat

Reputation: 4957

There is no right or left function, but you can implement the same functionality with substr, like this:

left(column, nchar) = substr(column, 1* nchar)

right(column, nchar) = substr(column, (-1)* nchar)

Here nchar is number of characters.

Upvotes: 39

ALEKSEY NIKITOV
ALEKSEY NIKITOV

Reputation: 61

right(column, nchar) = substr(column, (length(column)-nchar+1), nchar)

Upvotes: 6

jose_bacoy
jose_bacoy

Reputation: 12684

This works: substr (col, -nchar) = right(col, nchar).

hive> select substr('adbcefghij',-4);
ghij
Time taken: 40.839 seconds, Fetched: 1 row(s)

Upvotes: 9

Related Questions