Exception Handling in PL/SQL Last Updated : 28 Apr, 2018 Comments Improve Suggest changes Like Article Like Report An exception is an error which disrupts the normal flow of program instructions. PL/SQL provides us the exception block which raises the exception thus helping the programmer to find out the fault and resolve it. There are two types of exceptions defined in PL/SQL User defined exception. System defined exceptions. Syntax to write an exception WHEN exception THEN statement; DECLARE declarations section; BEGIN executable command(s); EXCEPTION WHEN exception1 THEN statement1; WHEN exception2 THEN statement2; [WHEN others THEN] /* default exception handling code */ END; Note: When other keyword should be used only at the end of the exception handling block as no exception handling part present later will get executed as the control will exit from the block after executing the WHEN OTHERS. System defined exceptions: These exceptions are predefined in PL/SQL which get raised WHEN certain database rule is violated. System-defined exceptions are further divided into two categories: Named system exceptions. Unnamed system exceptions. Named system exceptions: They have a predefined name by the system like ACCESS_INTO_NULL, DUP_VAL_ON_INDEX, LOGIN_DENIED etc. the list is quite big. So we will discuss some of the most commonly used exceptions: Lets create a table geeks. create table geeks(g_id int , g_name varchar(20), marks int); insert into geeks values(1, 'Suraj',100); insert into geeks values(2, 'Praveen',97); insert into geeks values(3, 'Jessie', 99); NO_DATA_FOUND: It is raised WHEN a SELECT INTO statement returns no rows. For eg: SQL DECLARE temp varchar(20); BEGIN SELECT g_id into temp from geeks where g_name='GeeksforGeeks'; exception WHEN no_data_found THEN dbms_output.put_line('ERROR'); dbms_output.put_line('there is no name as'); dbms_output.put_line('GeeksforGeeks in geeks table'); end; Output: ERROR there is no name as GeeksforGeeks in geeks table TOO_MANY_ROWS:It is raised WHEN a SELECT INTO statement returns more than one row. SQL DECLARE temp varchar(20); BEGIN -- raises an exception as SELECT -- into trying to return too many rows SELECT g_name into temp from geeks; dbms_output.put_line(temp); EXCEPTION WHEN too_many_rows THEN dbms_output.put_line('error trying to SELECT too many rows'); end; Output: error trying to SELECT too many rows VALUE_ERROR:This error is raised WHEN a statement is executed that resulted in an arithmetic, numeric, string, conversion, or constraint error. This error mainly results from programmer error or invalid data input. SQL DECLARE temp number; BEGIN SELECT g_name into temp from geeks where g_name='Suraj'; dbms_output.put_line('the g_name is '||temp); EXCEPTION WHEN value_error THEN dbms_output.put_line('Error'); dbms_output.put_line('Change data type of temp to varchar(20)'); END; Output: Error Change data type of temp to varchar(20) ZERO_DIVIDE = raises exception WHEN dividing with zero. SQL DECLARE a int:=10; b int:=0; answer int; BEGIN answer:=a/b; dbms_output.put_line('the result after division is'||answer); exception WHEN zero_divide THEN dbms_output.put_line('dividing by zero please check the values again'); dbms_output.put_line('the value of a is '||a); dbms_output.put_line('the value of b is '||b); END; Output: dividing by zero please check the values again the value of a is 10 the value of b is 0 Unnamed system exceptions:Oracle doesn't provide name for some system exceptions called unnamed system exceptions.These exceptions don't occur frequently.These exceptions have two parts code and an associated message. The way to handle to these exceptions is to assign name to them using Pragma EXCEPTION_INIT Syntax: PRAGMA EXCEPTION_INIT(exception_name, -error_number); error_number are pre-defined and have negative integer range from -20000 to -20999. Example: SQL DECLARE exp exception; pragma exception_init (exp, -20015); n int:=10; BEGIN FOR i IN 1..n LOOP dbms_output.put_line(i*i); IF i*i=36 THEN RAISE exp; END IF; END LOOP; EXCEPTION WHEN exp THEN dbms_output.put_line('Welcome to GeeksforGeeks'); END; Output: 1 4 9 16 25 36 Welcome to GeeksforGeeks User defined exceptions: This type of users can create their own exceptions according to the need and to raise these exceptions explicitly raise command is used. Example: Divide non-negative integer x by y such that the result is greater than or equal to 1. From the given question we can conclude that there exist two exceptions Division be zero. If result is greater than or equal to 1 means y is less than or equal to x. SQL DECLARE x int:=&x; /*taking value at run time*/ y int:=&y; div_r float; exp1 EXCEPTION; exp2 EXCEPTION; BEGIN IF y=0 then raise exp1; ELSEIF y > x then raise exp2; ELSE div_r:= x / y; dbms_output.put_line('the result is '||div_r); END IF; EXCEPTION WHEN exp1 THEN dbms_output.put_line('Error'); dbms_output.put_line('division by zero not allowed'); WHEN exp2 THEN dbms_output.put_line('Error'); dbms_output.put_line('y is greater than x please check the input'); END; Input 1: x = 20 y = 10 Output: the result is 2 Input 2: x = 20 y = 0 Output: Error division by zero not allowed Input 3: x=20 y = 30 Output:<.em> Error y is greater than x please check the input RAISE_APPLICATION_ERROR: It is used to display user-defined error messages with error number whose range is in between -20000 and -20999. When RAISE_APPLICATION_ERROR executes it returns error message and error code which looks same as Oracle built-in error. Example: SQL DECLARE myex EXCEPTION; n NUMBER :=10; BEGIN FOR i IN 1..n LOOP dbms_output.put_line(i*i); IF i*i=36 THEN RAISE myex; END IF; END LOOP; EXCEPTION WHEN myex THEN RAISE_APPLICATION_ERROR(-20015, 'Welcome to GeeksForGeeks'); END; Output: Error report: ORA-20015: Welcome to GeeksForGeeks ORA-06512: at line 13 1 4 9 16 25 36 Note: The output is based on Oracle Sql developer, the output order might change IF you're running this code somewhere else. Scope rules in exception handling: We can't DECLARE an exception twice but we can DECLARE the same exception in two dIFferent blocks. Exceptions DECLAREd inside a block are local to that block and global to all its sub-blocks. As a block can reference only local or global exceptions, enclosing blocks cannot reference exceptions DECLAREd in a sub-block. If we reDECLARE a global exception in a sub-block, the local declaration prevails i.e. the scope of local is more. Example: SQL DECLARE GeeksforGeeks EXCEPTION; age NUMBER:=16; BEGIN -- sub-block BEGINs DECLARE -- this declaration prevails GeeksforGeeks EXCEPTION; age NUMBER:=22; BEGIN IF age > 16 THEN RAISE GeeksforGeeks; /* this is not handled*/ END IF; END; -- sub-block ends EXCEPTION -- Does not handle raised exception WHEN GeeksforGeeks THEN DBMS_OUTPUT.PUT_LINE ('Handling GeeksforGeeks exception.'); WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE ('Could not recognize exception GeeksforGeeks in this scope.'); END; Output: Could not recognize exception GeeksforGeeks in this scope. Advantages: Exception handling is very useful for error handling, without it we have to issue the command at every point to check for execution errors: Example: Select .. .. check for 'no data found' error Select .. .. check for 'no data found' error Select .. .. check for 'no data found' error Here we can see that it is not robust as error processing is not separated from normal processing and IF we miss some line in the code than it may lead to some other kind of error. With exception handling we handle errors without writing statements multiple times and we can even handle dIFferent types of errors in one exception block: Example: BEGIN SELECT ... SELECT ... SELECT ... . . . exception WHEN NO_DATA_FOUND THEN /* catches all 'no data found' errors */ ... WHEN ZERO_DIVIDE THEN /* different types of */ WHEN value_error THEN /* errors handled in same block */ ... From above code we can conclude that exception handling Improves readability by letting us isolate error-handling routines and thus providing robustness. Provides reliability, instead of checking for dIFferent types of errors at every point we can simply write them in exception block and IF error exists exception will be raised thus helping the programmer to find out the type of error and eventually resolve it. Uses: One of the real lIFe use of exception can be found in online train reservation system. While filling the station code to book the ticket IF we input wrong code it shows us the exception that the code doesn't exist in database. Reference: You can find the list of all pre-defined exception here. Total number of pre-defined exceptions Comment More infoAdvertise with us Next Article PostgreSQL - Assert S SrjSunny Follow Improve Article Tags : PL/SQL Similar Reads BasicsPostgreSQL TutorialIn this PostgreSQL tutorial youâll learn the basic data types(Boolean, char, text, time, int etc.), Querying and Filtering techniques like select, where, in, order by, etc. managing and modifying the tables in PostgreSQL. Weâll cover all the basic to advance concepts of PostgreSQL in this tutorial.8 min readWhat is PostgreSQL - IntroductionThis is an introductory article for the PostgreSQL database management system. In this we will look into the features of PostgreSQL and why it stands out among other relational database management systems. Brief History of PostgreSQL: PostgreSQL also known as Postgres, was developed by Michael Stone2 min readInstall PostgreSQL on WindowsInstalling PostgreSQL on your Windows 10 machine is straightforward with the PostgreSQL installer. In this article, we'll walk you through installing PostgreSQL version 11.3, ensuring a smooth setup process.Steps to Install PostgreSQL on WindowsThere are three crucial steps for the installation of P2 min readInstall PostgreSQL on MacInstalling PostgreSQL on Mac OS can enhance our development environment, providing a robust relational database management system. In this article, we will focus on installing PostgreSQL version 11.3 using the installer provided by EnterpriseDB. This step-by-step guide will ensure a smooth installat3 min readDatabase OperationsPostgreSQL - Create DatabaseCreating a database in PostgreSQL is an important task for developers and database administrators to manage data effectively. PostgreSQL provides multiple ways to create a database, catering to different user preferences, whether through the command-line interface or using a graphical interface like5 min readPostgreSQL - Loading a DatabaseIn this article we will look into the process of loading a PostgreSQL database into the PostgreSQL database server. Before moving forward we just need to make sure of two things: PostgreSQL database server is installed on your system. A sample database. For the purpose of this article, we will be us3 min readPostgreSQL ALTER DATABASEThe PostgreSQL ALTER DATABASE statement is a powerful tool used for modifying an existing database.  The features of a database, once created can be changed using the ALTER DATABASE statement. Let's explore the syntax of PostgreSQL ALTER DATABASE, the various actions that can be performed, and pract3 min readPostgreSQL - Rename DatabaseRenaming a PostgreSQL database is a simple yet essential task for developers and database administrators. Whether we're migrating data, restructuring our database, or just managing our server efficiently, the ability to rename a PostgreSQL database can streamline our workflow. In this article, we wi4 min readPostgreSQL - Show DatabasesIn PostgreSQL, viewing a list of all databases on a server requires specific commands, as it doesnât support a direct SHOW DATABASES statement like MySQL. Instead, you can use the \l or \l+ commands in psql or query the pg_database view to display all databases. In this article, we will guide us thr3 min readData TypesPostgreSQL - Data TypesPostgreSQL is a powerful, open-source relational database management system that supports a wide variety of data types. These data types are essential for defining the nature of the data stored in a database column. which allows developers to define, store, and manipulate data in a way that aligns w5 min readPostgreSQL - Boolean Data TypePostgreSQL's Boolean data type supports three states: TRUE, FALSE, and NULL. It uses a single byte to store Boolean values and can be abbreviated as BOOL. In this article, we will explain the PostgreSQL BOOLEAN data type and its implementation in database table design, highlighting its usage through4 min readPostgreSQL - CHAR Data TypeThe CHAR data type in PostgreSQL is one of the essential character data types for storing fixed-length strings. Unlike VARCHAR, which stores variable-length data, CHAR is used when we need to store a fixed-length string.This article will explain the CHAR data type in PostgreSQL, its syntax, common u5 min readPostgreSQL - VARCHAR Data TypeIn the world of relational databases, PostgreSQL stands out with its robust support for various data types, including the flexible VARCHAR data type. This character data type allows us to store strings of variable length, making it an essential choice for many applications.In this article, we will e3 min readPostgreSQL - NUMERIC Data TypeIn PostgreSQL, the NUMERIC data type is designed for high-precision number storage by making it ideal for financial and scientific applications where accuracy is critical. It supports a large number of digits both before and after the decimal point, minimizing rounding errors. Understanding the nuan5 min readPostgreSQL - Date Data TypePostgreSQL offers powerful DATE data type and date functions to efficiently handle date and time information. PostgreSQL DATE data type allows for storing and manipulating calendar dates while its robust set of date functions enables users to perform operations like date arithmetic and formatting. I4 min readPostgreSQL - TIME Data TypeIn PostgreSQL, the TIME data type is essential for applications that require precise time tracking, such as scheduling systems and event logging. This data type allows for accurate time-based entries without storing date information. PostgreSQLâs TIME data type also supports fractional seconds for u4 min readPostgreSQL - JSON Data TypeJSON (JavaScript Object Notation) is a widely used format for storing data in the form of key-value pairs. Its popularity comes from being easy for humans to read and understand, making it ideal for communication between servers and clients. This readability and ease of use have made JSON a standard4 min readPostgreSQL - CREATE DOMAINPostgreSQL supports the creation of user-defined data types through the CREATE DOMAIN and CREATE TYPE statements. These capabilities allow for the customization and extension of data types to fit specific application needs, providing more flexibility and control over data integrity and consistency.3 min readQuerying TablesPostgreSQL - SELECTPostgreSQL SELECT statement is an command for retrieving data from tables within a PostgreSQL database. It enables users to specify which columns to fetch and apply filters using the WHERE clause for targeted results.In this article, We will learn about the PostgreSQL SELECT in detail by understandi3 min readPostgreSQL - ORDER BY clauseThe PostgreSQL ORDER BY clause is used to sort the result query set returned by the SELECT statement. As the query set returned by the SELECT statement has no specific order, one can use the ORDER BY clause in the SELECT statement to sort the results in the desired manner. Syntax: SELECT column_1, c2 min readPostgreSQL - WHERE clauseThe PostgreSQL WHERE clause is a critical component of SQL queries, allowing users to filter records based on specified conditions. In this tutorial, we'll explore how the WHERE clause works in PostgreSQL, its integration with the SELECT statement, and various examples. By using the WHERE clause, we6 min readPostgreSQL FETCH ClauseThe PostgreSQL FETCH clause is an essential feature for controlling and managing the number of rows returned in our SQL queries. It provides a standardized approach for limiting results, similar to the LIMIT clause but with more flexibility and compatibility across different database systems. This a4 min readPostgreSQL - IN operatorThe IN operator in PostgreSQL is a powerful and efficient tool used to filter records based on a predefined set of values. When used with the WHERE clause, it simplifies SQL queries and enhances readability, making it a key component of SQL query optimization for data retrieval and database manipula4 min readPostgreSQL - HAVING clauseThe HAVING clause in PostgreSQL is an essential feature for filtering grouped data that has been aggregated using functions like SUM(), COUNT(), AVG(), and others. Unlike the WHERE clause, which filters rows before aggregation, the HAVING clause is used to filter results after the grouping and aggre4 min readPostgreSQL - GROUP BY clauseThe GROUP BY clause in PostgreSQL is an essential tool that allows us to group rows that share the same values in one or more columns. This powerful functionality is commonly used to perform aggregate calculations such as SUM(), COUNT(), AVG(), and more, enabling us to summarize data efficiently. In4 min readPostgreSQL - LIKE operatorIn PostgreSQL, the LIKE operator is an essential tool for pattern matching in SQL queries. Whether we're dealing with large datasets or searching for specific string patterns, this operator provides a powerful way to filter and retrieve data based on partial matches. By Using wildcard search techniq5 min readPostgreSQL - BETWEEN OperatorThe PostgreSQL BETWEEN operator is an essential tool for filtering data within a specific range. Often used in the WHERE clause of SELECT, INSERT, UPDATE, and DELETE statements, this operator simplifies range-based conditions, making queries faster and easier to read. In this article, we will explai3 min readTable OperationsPostgreSQL - CREATE TABLEIn PostgreSQL, the CREATE TABLE statement is used to define a new table within a database. It allows us to specify the table's structure, including column names, data types, and constraints, ensuring data integrity and consistency. Understanding the PostgreSQL table creation process is essential for5 min readPostgreSQL - SELECT INTOThe PostgreSQL SELECT INTO statement allows users to create a new table directly from the result set of a query. This command is ideal for duplicating or organizing data from an existing table into a new one for further analysis. SELECT INTO does not return data to the client but saves it in a new t4 min readPostgreSQL - CREATE SEQUENCEIn database management, generating unique identifiers is vital for data integrity, and PostgreSQL provides a powerful feature called CREATE SEQUENCE to solve this. This command allows developers to create a sequence that automatically generates unique numeric values. In this article, we will explore4 min readPostgreSQL - ALTER TABLEIn PostgreSQL, the ALTER TABLE statement is a powerful and essential tool that allows us to modify the structure of an existing table to meet evolving database needs. With PostgreSQL ALTER TABLE, we can perform various modifications on the table without disrupting the ongoing operations of our datab6 min readPostgreSQL - ADD COLUMNIn PostgreSQL, the ADD COLUMN statement is a powerful command used to modify an existing database table by adding one or more new columns. This feature is important for adapting table structures to meet evolving data requirements, and it plays a key role in database management and optimization.In th4 min readPostgreSQL - DROP COLUMNIn PostgreSQL, there are instances where you might need to remove unnecessary or obsolete columns from your database tables. The DROP COLUMN clause in the ALTER TABLE statement allows you to do this with ease. When you drop a column from a table, PostgreSQL automatically removes any associated index2 min readPostgreSQL - Rename TableRenaming a table in PostgreSQL is a common task that can be quickly done using the RENAME clause in combination with the ALTER TABLE statement. This article will walk you through the process of renaming an existing table in PostgreSQL, explaining the syntax, and providing a detailed example.SyntaxAL2 min readPostgreSQL - DROP TABLEIn PostgreSQL, the DROP TABLE statement is a powerful and permanent command used to delete one or more tables from a database. Since this operation cannot be undone, it is essential to understand how to use it safely and to be aware of its options to prevent accidental data loss. In this article, we5 min readPostgreSQL - TRUNCATE TABLEIn PostgreSQL, the TRUNCATE TABLE statement provides a quick and efficient way to remove all data from large tables, freeing up storage space instantly. Unlike the DELETE statement, which removes rows one by one and logs each deletion, TRUNCATE TABLE is optimized for performance, especially with lar4 min readPostgreSQL - Copy a TableThis article will focus on copying an existing table to a new table in PostgreSQL. This might come in handy while creating new tables that would either have the same data or data of the same table with certain operations performed on them.Ways to Copy a TableWe will discuss the following 3 cases to3 min readPostgreSQL - Comparing TablesComparing tables in PostgreSQL is a common task when you need to identify differences between datasets. This can be especially useful when you are merging tables, validating data, or performing quality checks. In this article, we'll explore two of the most commonly used techniques for comparing tabl3 min readPostgreSQL - Show TablesIn PostgreSQL, viewing tables is an essential task for managing and organizing our database. Although PostgreSQL does not support the SHOW TABLES command like MySQL, it offers alternative commands like \dt in the psql tool, which helps users list all tables within a specific databaseIn this article,4 min readModifying DataPostgreSQL - INSERTPostgreSQL INSERT statement is one of the fundamental SQL commands used to add new rows to a specified table within a PostgreSQL database. This command allows users to insert data efficiently, whether for a single record or multiple records at once. With the PostgreSQL INSERT INTO clause, we can spe4 min readPostgreSQL - Insert Multiple Values in Various RowsPostgreSQL, one of the most popular relational database management systems (RDBMS), is widely used for storing structured data in a tabular format, much like MySQL. In relational databases, data is stored in tables where each row represents a record and each column represents an attribute. One of th3 min readPostgreSQL UPDATE StatementThe PostgreSQL UPDATE statement is an important SQL command used to modify existing data in one or more rows of a table. It allows users to update specific columns or multiple columns at once, using conditions defined in the WHERE clause. This command is highly flexible, enabling dynamic data manage5 min readPostgreSQL - DELETEThe DELETE statement is a key command in PostgreSQL used to remove existing records from a table. By using DELETE, you can eliminate unwanted or outdated records, helping keep your database organized and up to date.In this article, we will explore the DELETE statement, its syntax, and some practical4 min readPostgreSQL - UpsertUPSERT in PostgreSQL is a powerful database operation that merges the functionalities of INSERT and UPDATE into a single command. This operation allows users to either insert a new row into a table or update an existing row if it already exists.Also, making it essential for efficient data management4 min readConditionalsPostgreSQL - CASEIn PostgreSQL, the CASE expression allows you to perform conditional operations within your SQL queries. It evaluates a list of conditions and returns a result when the first condition is met. If no conditions are met, it returns the result specified in the ELSE clause.Let us better understand the C3 min readPostgreSQL COALESCEHandling NULL values effectively is important in database management, and PostgreSQL offers a powerful function called COALESCE to address this issue. The COALESCE function returns the first non-null argument among its parameters, making it particularly useful in SELECT statements.In this article, w5 min readPostgreSQL - NULLIF() FunctionEffectively handling NULL values is important in database management, especially for ensuring data integrity and avoiding errors. PostgreSQL offers several powerful functions, such as NULLIF and COALESCE, to help manage NULL and empty values efficiently. In this article, we will guide us through the4 min readPostgreSQL - CASTThe PostgreSQL CAST function provides an efficient way to convert data types in PostgreSQL, which is important when ensuring data is in the correct format for storage, calculations, or comparisons. In PostgreSQL, we can use CAST to transform data between various data types, such as converting string3 min readControl FlowPostgreSQL - IF StatementPostgreSQL IF statement is an essential tool for implementing conditional logic within SQL queries and stored procedures. It allows developers to execute different actions based on specific conditions and enhances the flexibility of database operations. In this article, we will explore various Postg5 min readPostgreSQL - CASE StatementIn PostgreSQL, CASE statements provide a way to implement conditional logic within SQL queries. Using these statements effectively can help streamline database functions, optimize query performance, and provide targeted outputs. This guide will break down the types of CASE statements available in Po4 min readPostgreSQL - Loop StatementThe LOOP statement in PL/pgSQL is used to create an unconditional loop that executes a block of code repeatedly until a RETURN or EXIT statement terminates it. This article will help you understand the syntax and usage of the LOOP statement, and provide examples to display its application.Let us get3 min readPostgreSQL - While LoopsWhen working with PostgreSQL, knowing how to efficiently use loops can be essential for running iterative operations. PostgreSQLâs WHILE loop allows developers to repeatedly execute a block of code as long as a specified condition remains true. PostgreSQL provides the loop statement which simply def4 min readPostgreSQL - Exit StatementIn PostgreSQL, the EXIT statement is a powerful tool used to terminate loops and blocks of code. This functionality is essential for managing control flow within your PostgreSQL scripts, allowing for more efficient and readable code. Let us get a better understanding of the usage of the EXIT stateme3 min readPostgreSQL - ContinueThe CONTINUE statement in PostgreSQL is used to prematurely skip the current iteration of a loop and proceed directly to the next iteration. This functionality applies to all types of loops, including unconditional loops, WHILE loops, and FOR loops.Let us get a better understanding of the CONTINUE s3 min readTransactions & ConstraintsPostgreSQL - TransactionsA transaction in database terminology is not a new concept. Similar to familiar terms such as "cash transaction" in banking, a transaction in the context of databases like PostgreSQL is a unit of work that ensures data integrity and consistency. Transactions are fundamental when you need to add, del4 min readPostgreSQL - COMMITThe COMMIT command in PostgreSQL is important for saving the changes made during a transaction. Without executing a COMMIT, all the data manipulation operations performed within the transaction will be lost once the session ends. It ensures that the changes made to the database are permanent and vis4 min readPostgreSQL - Primary KeyA primary key in PostgreSQL is a column (or a set of columns) that uniquely identifies each row in a table. It is an important component for ensuring data integrity and plays an important role in database normalization. When we define a primary key in PostgreSQL, the database automatically creates a4 min readPostgreSQL - Foreign KeyForeign keys play a crucial role in relational databases by establishing relationships between tables and safeguarding data integrity. In this PostgreSQL foreign key tutorial, we'll cover how foreign keys work, their importance and how to create them. We will also learn about foreign key constraints5 min readPostgreSQL - CHECK ConstraintIn PostgreSQL, the CHECK constraint is a powerful tool used to enforce data integrity by specifying that a value in a column must meet a specific requirement. The CHECK constraint uses a Boolean expression to evaluate the values before performing an insert or update operation on the column. If the v2 min readPostgreSQL - UNIQUE ConstraintIn PostgreSQL, the UNIQUE constraint is a powerful tool used to ensure that values stored in a column or a group of columns are unique across rows in a table. This constraint is essential for maintaining data integrity, especially when certain data should not be duplicated. For instance, if you're s3 min readPostgreSQL - NOT NULL ConstraintIn PostgreSQL, the NOT NULL constraint is a fundamental feature to ensure that a column cannot contain NULL values. NULL represents unknown or missing information in databases, distinct from an empty string or the number zero. For example, if you ask someone for their email address and they donât kn3 min readJOINS & SchemasPostgreSQL - JoinsThe PostgreSQL JOIN statement is a powerful tool for combining data or rows from one or more tables based on a common field between them. These common fields are typically the primary key in the first table and the foreign key in the other table(s). By using different types of JOINs, we can perform5 min readPostgreSQL - LEFT JOINIn PostgreSQL, the LEFT JOIN (or LEFT OUTER JOIN) is a powerful tool that allows you to merge data from two tables based on a related column. With a LEFT JOIN, you get all records from the "left" table and matching records from the "right" table. If thereâs no match in the right table, NULL values w5 min readPostgreSQL - INNER JOINIn PostgreSQL the INNER JOIN keyword selects all rows from both the tables as long as the condition satisfies. This keyword will create the result-set by combining all rows from both the tables where the condition satisfies i.e value of the common field will be the same. Syntax: SELECT table1.column2 min readPostgreSQL - FULL OUTER JOINIn PostgreSQL, the FULL OUTER JOIN is a powerful feature that combines the effects of both LEFT JOIN and RIGHT JOIN. This join operation retrieves all rows from both tables involved in the join, including unmatched rows from each table. For any unmatched rows, PostgreSQL fills the result with NULL v4 min readPostgreSQL - SELF JOINIn PostgreSQL, a SELF JOIN is a powerful technique that allows us to join a table with itself. This type of join is particularly useful for comparing rows within the same table, such as establishing hierarchical relationships or identifying duplicate records. Unlike other joins, there is no specific4 min readPostgreSQL - SchemaPostgreSQL is a powerful, open-source relational database management system (RDBMS) that is widely used for managing data. One of the most important concepts in PostgreSQL is the schema. A schema is a way of organizing database objects like tables, views, indexes, functions, and data types. In this5 min readPostgreSQL - CREATE SCHEMAPostgreSQL provides the CREATE SCHEMA statement to create a new schema in a database. By creating schemas, users can effectively separate data into logical groups, making it easier to manage and access information. Schemas also enhance security by controlling object visibility and permissions, allow5 min readPostgreSQL - DROP SCHEMAPostgreSQL offers a powerful schema management system, allowing database administrators to organize and manage objects within specific schemas. The DROP SCHEMA statement in PostgreSQL provides a straightforward way to delete entire schemas and the associated objects, making it a valuable tool for da4 min readPostgreSQL - ALTER SCHEMAIn PostgreSQL, the ALTER SCHEMA statement is a powerful tool that allows you to modify the definition of an existing schema. By understanding how to use ALTER SCHEMA effectively is crucial for managing your database schemas. This article will provide a detailed exploration of the ALTER SCHEMA statem3 min read Like