RIGHT
Description
Returns the right part of a character string with the specified number of characters. (RIGHT in Transact-SQL).
Sample Source Pattern
Syntax
RIGHT ( character_expression , integer_expression ) Snowflake SQL complete documentation
RIGHT( <expr> , <length_expr> )UDF used to emulate the behavior
function RIGHT(string, index){
if(index< 0){
throw new RangeError('Invalid INDEX on RIGHT function');
}
return string.slice( string.length - index, string.length );
}Examples
Code:
SELECT RIGHT('John Smith', 5) AS LAST_NAME;Output:
LAST_NAME|
------------+
Smith| Code:
SELECT RIGHT('John Smith', 5) AS LAST_NAME;Output:
LAST_NAME|
------------+
Smith| Code:
CREATE OR REPLACE FUNCTION right_str(str varchar, index float)
RETURNS string
LANGUAGE JAVASCRIPT
AS
$$
function RIGHT(string, index){
if(index< 0){
throw new RangeError('Invalid INDEX on RIGHT function');
}
return string.slice( string.length - index, string.length );
}
return RIGHT(STR, INDEX);
$$;
SELECT RIGHT_STR('John Smith', 5) AS LAST_NAME;Output:
LAST_NAME|
------------+
Smith| Last updated