Skip to content

Instantly share code, notes, and snippets.

@barsbek
Created March 16, 2018 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barsbek/0f9e4a91a6abebd2d5352a791bd66c8a to your computer and use it in GitHub Desktop.
Save barsbek/0f9e4a91a6abebd2d5352a791bd66c8a to your computer and use it in GitHub Desktop.
postgresql: fill up or truncate the string to length
rpad(string text, length int [, fill text])
fill is space by default
select rpad('hello', 10, 'w') -- hellowwwww
select lpad('hello', 10, 'p') -- ppppphello
select lpad('hello', 10) -- ' hello'
select rpad('hello', 4) -- hell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment