REPEAT
Repeats a string the given number of times.
PostgreSQL 17.5
REPEAT(string, count)Parameters
- stringtext
- Source string
- countinteger
- Number of repetitions
Return value
A string of count repetitions; an empty string if count is less than 1
Examples
String three times in a row
PostgreSQL 17.5
SELECT REPEAT('Pg', 3);Payment count as a bar of asterisks
PostgreSQL 17.5
SELECT family_member,
COUNT(*) AS payments,
REPEAT('*', COUNT(*)::integer) AS bar
FROM Payments
GROUP BY family_member
ORDER BY family_member;Details
The function is good for simple text charts: REPEAT('*', n) draws a bar of n asterisks. count must be integer, so the result of COUNT (a bigint) is cast with ::integer.