We're Moving!

The Vertica Forum is moving to a new OpenText Analytics Database (Vertica) Community.

Join us there to post discussion topics, learn about

product releases, share tips, access the blog, and much more.

Create My New Community Account Now


Insert Spaces Into a Character String — Vertica Forum

Insert Spaces Into a Character String

Jim_KnicelyJim_Knicely - Select Field - Administrator
edited November 2018 in Tips from the Team

In many SQL relational database you will have to use the RPAD function to insert spaces into a character string. That also works in Vertica. However, for a more robust solution, Vertica provides the built-in function SPACE which returns the specified number of blank spaces.

Example:

dbadmin=> SELECT 'ABC' || RPAD(' ', 10, ' ') || 'DEF' "Insert 10 spaces!";
Insert 10 spaces!
-------------------
ABC          DEF
(1 row)

dbadmin=> SELECT 'ABC' || SPACE(10) || 'DEF' "Insert 10 spaces!";
Insert 10 spaces!
-------------------
ABC          DEF
(1 row)

dbadmin=> SELECT 'My girlfriend broke up with me because she said she needed ' || SPACE(10) || '!?!?' AS "?";
                                     ?
---------------------------------------------------------------------------
My girlfriend broke up with me because she said she needed           !?!?
(1 row)

Helpful Links:
https://www.vertica.com/docs/9.1.x/HTML/index.htm#Authoring/SQLReferenceManual/Functions/String/SPACE.htm
https://www.vertica.com/docs/9.1.x/HTML/index.htm#Authoring/SQLReferenceManual/Functions/String/RPAD.htm

Have fun!

Sign In or Register to comment.