Return First ‘N’ character of the column in Postgresql

In order to return the first ‘N’ character of the column in postgresql we use LEFT() function. LEFT() function in postgresql returns the first n characters.Let’s see how to

  • Return first ‘N’ character of the column in postgresql using LEFT() function

Syntax of LEFT():

left(string,n)

We will be using Zipcodes table.

Return first n character of the column in postrgresql 1

 

Return First ‘N’ character of the column in Postgresql:

In order to return first n character of the column in postgresql. We use LEFT() function as shown below.

select *,LEFT(city,5) as first_n FROM zipcodes

Left function of city column extracts first 5 characters so the resultant dataframe will be

Return first n character of the column in postrgresql 2

                                                                                             

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.