Skip to content

LPAD

Fill a character string to a specified length on the left side with designated characters (spaces by default). If the string is already longer than the specified length, it is truncated on the right side. See also RPAD.

LPAD(string, length [ , characters ] )

For example, add a sequence of zeroes to the left side of the teamid column, for a length of 10 characters:

premdb=# SELECT LPAD(teamid::char(10),10,'0') FROM team;
   lpad    
------------
 0000000001
 0000000002
 0000000003
 0000000004
 0000000005
 0000000006
 0000000007
 0000000008
 0000000009
 0000000010
...

Parent topic:String Functions