Get string length of the column in Postgresql

In order to get the string length of the column in postgresql we use LENGTH() function or CHAR_LENGTH() function. Both these functions calculate the length of the string in postgresql. Let’s see how to

  • Get length of the string or character in postrgresql.

Syntax of LENGTH():

length()

Syntax of CHAR_LENGTH():

char_length (string)

We will be using summerfruits table.

Get string length of the column in Postgresql 1

 

Get string length of the column in Postgresql:

Method 1:

String length of the column in postgresl is extracted using LENGTH() function

select *, LENGTH(name) as Length from summerfruits

So the resultant dataframe will be

Get string length of the column in Postgresql 2

 

Method 2:

String length of the column in postgresl is extracted using CHAR_LENGTH() function

select *, CHAR_LENGTH(name) as Length from summerfruits

So the resultant dataframe will be

Get string length of the column in Postgresql 3

 

                                                                                               

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.