Vertica Quick Tip: Repeating

Posted March 13, 2018 by Soniya Shah, Information Developer

This blog post 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!