The Vertica Forum recently got a makeover! Let us know what you think by filling out this short, anonymous survey.
Please take this survey to help us learn more about how you use third party tools. Your input is greatly appreciated!
Repeating
![[Deleted User]](https://us.v-cdn.net/6029397/uploads/defaultavatar/nD0LWW9MQTB29.jpg)
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!
0