Please take this survey to help us learn more about how you use third party tools. Your input is greatly appreciated!

Repeating

This tip was authored by Jim Knicely.

The Vertica REPEAT function replicates a string the specified number of times, and concatenates the replicated values as a single string.

Examples:

dbadmin=> SELECT repeat('TesT', 5);
        repeat
----------------------
TesTTesTTesTTesTTesT
(1 row)

dbadmin=> SELECT '1' || repeat('0', 100) AS "One Googolplex";
                                            One Googolplex
-------------------------------------------------------------------------------------------------------
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
(1 row)

This function is also very useful if you plan on telling the old “Pete and Repete are on a boat” joke:

dbadmin=> SELECT repeat('Pete and Repete are in a boat. Pete jumps out. Who is left in the boat? Repete.' || CHR(10), 10);
                                                                                                                                                                                                                                                                                                                                                                                                              repeat                                                                                                                                                                                                                                                                
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Pete and Repete are in a boat. Pete jumps out. Who is left in the boat? Repete.
Pete and Repete are in a boat. Pete jumps out. Who is left in the boat? Repete.
Pete and Repete are in a boat. Pete jumps out. Who is left in the boat? Repete.
Pete and Repete are in a boat. Pete jumps out. Who is left in the boat? Repete.
Pete and Repete are in a boat. Pete jumps out. Who is left in the boat? Repete.
Pete and Repete are in a boat. Pete jumps out. Who is left in the boat? Repete.
Pete and Repete are in a boat. Pete jumps out. Who is left in the boat? Repete.
Pete and Repete are in a boat. Pete jumps out. Who is left in the boat? Repete.
Pete and Repete are in a boat. Pete jumps out. Who is left in the boat? Repete.
Pete and Repete are in a boat. Pete jumps out. Who is left in the boat? Repete.
(1 row)

Have Fun!

Sign In or Register to comment.

Can't find what you're looking for? Search the Vertica Documentation, Knowledge Base, or Blog for more information.