PostgreSQL REPEAT() function
REPEAT() function
The PostgreSQL repeat function is used to repeat a specified string to a specified number of times.
Syntax:
repeat(<string>,<repeating_number>)
PostgreSQL Version: 9.3
Pictorial Presentation of PostgreSQL REPEAT() function
Example: PostgreSQL REPEAT() function:
In the example below, the specified string 'test__' and '*--*' have repeated 5 times each.
Code:
SELECT repeat('test___', 5),repeat('*--*', 5);
Sample Output:
repeat | repeat --------------------------------+---------------------- test__test__test__test__test__ | *--**--**--**--**--* (1 row)
Example of PostgreSQL REPEAT() function using column :
Sample Table: employees
The example below returns a format using repeat function. Here in the example below the first_name and last_name have concatenated and a string has been concatenated after repeating a specific time from employees table for department_id 100.
Code:
SELECT concat(first_name,' ',last_name) "Name",
concat(repeat('-',3),'>>') " ",job_id "Designation"
FROM employees
WHERE department_id=100;
Sample Output:
Name | | Designation -------------------+-------+------------- Nancy Greenberg | --->> | FI_MGR Daniel Faviet | --->> | FI_ACCOUNT John Chen | --->> | FI_ACCOUNT Ismael Sciarra | --->> | FI_ACCOUNT Jose Manuel Urman | --->> | FI_ACCOUNT Luis Popp | --->> | FI_ACCOUNT (6 rows)
Previous: QUOTE_IDENT function
Next: REPLACE function
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook