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