functionLEFT(string, index){if(index <0){thrownewRangeError('Invalid INDEX on LEFT function'); }returnstring.slice( 0, index); }returnLEFT(STR,INDEX);
Examples
Code:
SELECTLEFT('John Smith', 5) AS FIRST_NAME
Output:
FIRST_NAME|
----------+
John |
Code:
SELECTRIGHT('John Smith', 5) AS LAST_NAME
Output:
FIRST_NAME|
----------+
John |
Code:
CREATEORREPLACEFUNCTIONleft_str(str varchar, index float)RETURNS stringLANGUAGEJAVASCRIPTAS$$functionLEFT(string, index){if(index <0){thrownewRangeError('Invalid INDEX on LEFT function'); }returnstring.slice( 0, index); }returnLEFT(STR,INDEX);$$;SELECTLEFT_STR('John Smith',5) ASFIRST_NAME;