PostgreSQL – LEFT Function

The LEFT function in postgreSQL is used to extract a specified number of characters from the beginning (left side) of a string. The syntax of the LEFT function is as follows:

LEFT(string, length)

where string is the input string from which you want to extract characters,

and length is the number of characters you want to extract from the left side of the input string.

Here’s an example of how you might use the LEFT function in a SQL query:

SELECT LEFT('Hello, World!', 5);

In this example, the result would be the string 'Hello', because the LEFT function extracted the first 5 characters from the input string.

Keep in mind that if the specified length is greater than the length of the input string, the LEFT function will simply return the entire input string.

SELECT LEFT('Hi', 5);

In this case, the result would still be the string 'Hi', because the length of the input string is less than the specified length.

Similar Posts