Reputation: 1675
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
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
Reputation: 61
right(column, nchar) = substr(column, (length(column)-nchar+1), nchar)
Upvotes: 6
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