Comprehensive Guide to writing PL/pgSQL Functions in PostgreSQL
This resource offers a total of 50 PostgreSQL Writing PL/pgSQL functions problems for practice. It includes 10 main exercises, each accompanied by solutions, detailed explanations, and four related problems.
1. Create a Simple Function to Return a Constant Value
Write a PostgreSQL function that returns the string "Hello, PostgreSQL!" when called.
2. Function to Calculate the Square of a Number
Write a PostgreSQL function that takes an integer as input and returns its square.
3. Function to Get Employee Full Name
Write a PostgreSQL function that concatenates an employee’s first name and last name from the Employees table.
4. Function to Check if a Number is Even or Odd
Write a PostgreSQL function that checks if a number is even or odd and returns a corresponding message.
5. Function to Calculate Factorial of a Number
Write a PostgreSQL function to calculate the factorial of a given integer.
6. Function to Count Employees in a Department
Write a PostgreSQL function that returns the count of employees in a specific department.
7. Function to Reverse a String
Write a PostgreSQL function to reverse a given string.
8. Function to return the Current Date and Time
Write a PostgreSQL function to return the current timestamp.
9. Function to Get the Highest Salary in a Department
Write a PostgreSQL function to return the highest salary from a given department.
10. Function to Get the Number of Days Between Two Dates
Write a PostgreSQL function that calculates the number of days between two given dates.
More to Come !
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics