The INSERT Function

Moderator: NorbertKrupa

Post Reply
User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

The INSERT Function

Post by JimKnicely » Thu Aug 09, 2012 2:51 pm

The INSERT function inserts a character string into a specified location in another character string.

The syntax for the function is INSERT('string1', n, m, 'string2') where …
  • 1. string1 is a VARCHAR string in which to insert the new string.
    2. n is an INTEGER that represents the starting point for the insertion within string1.
    3. m is an INTEGER that represents the number of characters in string1 (if any) that should be replaced by the insertion.
    4. string2 is a VARCHAR string to be inserted.
Examples:

Code: Select all

dbadmin=> SELECT insert('I forgot something', 1, 0, 'Oops...');
          insert
---------------------------
Oops...I forgot something
(1 row)

Code: Select all

dbadmin=> SELECT insert('THIS IS A FIXED WIDTH STRING', 11, 12, '');
      insert
------------------
THIS IS A STRING
(1 row)

Code: Select all

dbadmin=> SELECT insert('A 3% pay increase is planned for all DBAs', 3, 1, '100');
                   insert
---------------------------------------------
A 100% pay increase is planned for all DBAs
(1 row)
Have fun!
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

Post Reply

Return to “Vertica Tips, Lessons and Examples”