w3resource

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.

Click me to see the solution

2. Function to Calculate the Square of a Number

Write a PostgreSQL function that takes an integer as input and returns its square.

Click me to see the solution

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.

Click me to see the solution

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.

Click me to see the solution

5. Function to Calculate Factorial of a Number

Write a PostgreSQL function to calculate the factorial of a given integer.

Click me to see the solution

6. Function to Count Employees in a Department

Write a PostgreSQL function that returns the count of employees in a specific department.

Click me to see the solution

7. Function to Reverse a String

Write a PostgreSQL function to reverse a given string.

Click me to see the solution

8. Function to return the Current Date and Time

Write a PostgreSQL function to return the current timestamp.

Click me to see the solution

9. Function to Get the Highest Salary in a Department

Write a PostgreSQL function to return the highest salary from a given department.

Click me to see the solution

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.

Click me to see the solution

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.



Follow us on Facebook and Twitter for latest update.