totn PostgreSQL Functions

PostgreSQL: length Function

This PostgreSQL tutorial explains how to use the PostgreSQL length function with syntax and examples.

Description

The PostgreSQL length function returns the length of the specified string, expressed as the number of characters.

Syntax

The syntax for the length function in PostgreSQL is:

length( string )

Parameters or Arguments

string
The string to return the length for.

Note

Applies To

The length function can be used in the following versions of PostgreSQL:

  • PostgreSQL 9.4, PostgreSQL 9.3, PostgreSQL 9.2, PostgreSQL 9.1, PostgreSQL 9.0, PostgreSQL 8.4

Example

Let's look at some PostgreSQL length function examples and explore how to use the length function in PostgreSQL.

For example:

postgres=# SELECT length('Tech on the Net');
 length
--------
     15
(1 row)

postgres=# SELECT length('techonthenet.com');
 length
--------
     16
(1 row)

postgres=# SELECT length('');
 length
--------
      0
(1 row)

postgres=# SELECT length(' ');
 length
--------
      1
(1 row)

postgres=# SELECT length(NULL);
 length
--------
  <NULL>
(1 row)