Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
1.1.
What is COALESCE?
2.
Frequently Asked Questions
2.1.
How to check multiple conditions in PostgreSQL?
2.2.
What is $$ in PostgreSQL?
2.3.
What is the use of % in SQL?
3.
Conclusion
Last Updated: Mar 27, 2024
Medium

Postgresql Coalesce

Author Ravi Khorwal
0 upvote
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

Hi Ninjas!! Welcome to another blog on PostgreSQL.

Postgresql Coalesce

Today we will learn about Coalesce in PostgreSQL. PostgreSQL is a powerful, open-source object-relational database management system (ORDBMS). It is used to store data securely.

What is COALESCE?

The COALESCE function is used to handle the Null Values in a table. This function allows assigning specific values to Null Values during Database query. COALESCE conditional function can accepts number of arguments at a time ,If all the arguments are NULL in that case it returns the fist argument as not null.

Syntax:

COALESCE (argument_1, argument_2, …);

Example:

Consider the Following table:

table
Select Name, COALESCE(Marks, 0) as Marks from student;

In this example row 11 contains a null value. Using COALESCE on column marks the null value is replaced with 0.

Output:

Output Image

Example:

Consider table Placement_cell :

Here St_id 1011 contains a NULL value in the company column.

Placement_cell table
select company,coalesce(company,'NoINFO') from Placement_cell;

This query replaces the NULL value in company column to ‘NoINFO’.

OUTPUT:

output of coalesce query

Frequently Asked Questions

How to check multiple conditions in PostgreSQL?

You can check multiple conditions in PostgreSQL by using AND operator.

What is $$ in PostgreSQL?

The $$ is the specific substitute for using single quotes to avoid escaping of nested single quotes (recursively).

What is the use of % in SQL?

The percent sign (%) represents zero, one, or multiple characters.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Conclusion

In this article, we have discussed the details of Postgresql Coalesce with their examples.

We hope that the blog has helped you enhance your knowledge regarding Postgresql Coalesce. You can refer to our guided paths on the Coding Ninjas Studio platform to learn more about DSADBMSCompetitive ProgrammingPythonJavaJavaScript, etc. To practice and improve yourself in the interview, you can also check out Top 100 SQL problemsInterview experienceCoding interview questions, and the Ultimate guide path for interviews. Do upvote our blogs to help other ninjas grow. 

Previous article
Getting started with Postgresql
Next article
Elasticsearch vs Postgresql
Live masterclass