EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials PostgreSQL Tutorial PostgreSQL Operators
Secondary Sidebar
PostgreSQL Tutorial
  • Basic
    • What is PostgreSQL
    • PostgreSQL Features
    • How to Install PostgreSQL
    • PostgreSQL Versions
    • PostgreSQL Architecture
    • PostgreSQL GUI
    • Postgres Command-Line
    • PostgreSQL Variables
    • PostgreSQL Data Types
    • PostgreSQL NOT NULL
    • PostgreSQL Integer
    • PostgreSQL Boolean
    • PostgreSQL BIGINT
    • PostgreSQL NULLIF
    • PostgreSQL Administration
    • PostgreSQL Commands
    • PostgreSQL Operators
    • PostgreSQL IN Operator
    • Postgres like query
    • PostgreSQL encode
    • PostgreSQL Cheat Sheet
    • PostgreSQL List Databases
    • PostgreSQL Rename Database
  • Control Statement
    • PostgreSQL IF Statement
    • PostgreSQL if else
    • PostgreSQL CASE Statement
    • PostgreSQL LOOP
    • PostgreSQL For Loop
    • PostgreSQL While Loop
  • Joins
    • Joins in PostgreSQL
    • PostgreSQL Inner Join
    • PostgreSQL Outer Join
    • LEFT OUTER JOIN in PostgreSQL
    • PostgreSQL FULL OUTER JOIN
    • PostgreSQL LEFT JOIN
    • PostgreSQL Full Join
    • PostgreSQL Cross Join
    • PostgreSQL NATURAL JOIN
    • PostgreSQL UPDATE JOIN
  • Queries
    • PostgreSQL Queries
    • PostgreSQL INSERT INTO
    • PostgreSQL WHERE Clause
    • PostgreSQL WITH Clause
    • PostgreSQL ORDER BY
    • PostgreSQL ORDER BY Random
    • PostgreSQL ORDER BY DESC
    • PostgreSQL GROUP BY
    • PostgreSQL group_concat
    • PostgreSQL HAVING
    • PostgreSQL Recursive Query
  • Advanced
    • PostgreSQL Schema
    • Postgres List Schemas
    • PostgreSQL Drop Schema
    • PostgreSQL VARCHAR
    • Array in PostgreSQL
    • PostgreSQL DDL
    • PostgreSQL List Users
    • Postgres Default User
    • Postgres add user
    • PostgreSQL User Password
    • PostgreSQL log_statement
    • PostgreSQL repository
    • PostgreSQL shared_buffer
    • PostgreSQL String Functions
    • PostgreSQL Compare Strings
    • PostgreSQL Text Search
    • PostgreSQL TEXT
    • PostgreSQL String Array
    • PostgreSQL where in array
    • PostgreSQL Constraints
    • PostgreSQL UNIQUE Constraint
    • PostgreSQL CHECK Constraint
    • PostgreSQL INTERSECT
    • PostgreSQL Like
    • Cursors in PostgreSQL
    • PostgreSQL UNION ALL
    • Indexes in PostgreSQL
    • PostgreSQL Index Types
    • PostgreSQL REINDEX
    • PostgreSQL UNIQUE Index
    • PostgreSQL Clustered Index
    • PostgreSQL DROP INDEX
    • PostgreSQL DISTINCT
    • PostgreSQL FETCH
    • PostgreSQL RAISE EXCEPTION
    • PostgreSQL Auto Increment
    • Sequence in PostgreSQL
    • Wildcards in PostgreSQL
    • PostgreSQL Subquery
    • PostgreSQL Alias
    • PostgreSQL LIMIT
    • PostgreSQL Limit Offset
    • PostgreSQL LAG()
    • PostgreSQL Table
    • Postgres Show Tables
    • PostgreSQL Describe Table
    • PostgreSQL Lock Table
    • PostgreSQL ALTER TABLE
    • Postgres Rename Table
    • PostgreSQL List Tables
    • PostgreSQL TRUNCATE TABLE
    • PostgreSQL Table Partitioning
    • Postgres DROP Table
    • PostgreSQL Functions
    • PostgreSQL Math Functions
    • PostgreSQL Window Functions
    • Aggregate Functions in PostgreSQL
    • PostgreSQL Primary Key
    • Foreign Key in PostgreSQL
    • PostgreSQL Procedures
    • PostgreSQL Stored Procedures
    • PostgreSQL Views
    • PostgreSQL Materialized Views
    • Postgres Create View
    • PostgreSQL Triggers
    • PostgreSQL DROP TRIGGER
    • PostgreSQL Date Functions
    • PostgreSQL TO_DATE()
    • PostgreSQL datediff
    • PostgreSQL Timestamp
    • PostgreSQL CURRENT_TIMESTAMP()
    • PostgreSQL Notify
    • PostgreSQL LENGTH()
    • PostgreSQL blob
    • PostgreSQL Median
    • PostgreSQL kill query
    • PostgreSQL Formatter
    • PostgreSQL RANK()
    • PostgreSQL Select
    • PostgreSQL Average
    • PostgreSQL DATE_PART()
    • PostgreSQL EXECUTE
    • PostgreSQL COALESCE
    • PostgreSQL EXTRACT()
    • PostgreSQL Sort
    • PostgreSQL TO_CHAR
    • PostgreSQL Interval
    • PostgreSQL Number Types
    • PostgreSQL ROW_NUMBER
    • Alter Column in PostgreSQL
    • PostgreSQL Identity Column
    • PostgreSQL SPLIT_PART()
    • PostgreSQL CONCAT()
    • PostgreSQL replace
    • PostgreSQL TRIM()
    • PostgreSQL MAX
    • PostgreSQL DELETE
    • PostgreSQL Float
    • PostgreSQL OID
    • PostgreSQL log
    • PostgreSQL REGEXP_MATCHES()
    • PostgreSQL MD5 
    • PostgreSQL NOW()
    • PostgreSQL RANDOM
    • PostgreSQL round
    • PostgreSQL Trunc()
    • PostgreSQL TIME
    • PostgreSQL IS NULL
    • PostgreSQL CURRENT_TIME
    • PostgreSQL MOD()
    • Postgresql Count
    • PostgreSQL Datetime
    • PostgreSQL MIN()
    • PostgreSQL age()
    • PostgreSQL enum
    • PostgreSQL OR
    • PostgreSQL Wal
    • PostgreSQL NOT IN
    • PostgreSQL SET
    • PostgreSQL Current Date
    • PostgreSQL Compare Date
    • PostgreSQL SERIAL
    • PostgreSQL UUID
    • PostgreSQL Merge
    • PostgreSQL Database
    • PostgreSQL Clone Database
    • PostgreSQL Copy Database
    • PostgreSQL Show Databases
    • PostgreSQL Restore Database
    • PostgreSQL DROP DATABASE
    • PostgreSQL ALTER DATABASE
    • Postgres DROP Database
    • Postgres Dump Database
    • PostgreSQL OFFSET
    • PostgreSQL GRANT
    • PostgreSQL COMMIT
    • PostgreSQL ROLLUP
    • PostgreSQL JSON
    • EXPLAIN ANALYZE in PostgreSQL
    • PostgreSQL Temporary Table
    • PostgreSQL Show Tables
    • PostgreSQL cluster
    • PostgreSQL Replication
    • PostgreSQL Logical Replication
    • PostgreSQL flush privileges
    • PostgreSQL Tablespaces
    • CAST in PostgreSQL
    • PostgreSQL CTE
    • hstore in PostgreSQL
    • PostgreSQL Encryption
    • PostgreSQL DECODE()
    • PostgreSQL Vacuum
    • PostgreSQL EXCLUDE
    • Postgres Change Password
    • Postgres Delete Cascade
    • PostgreSQL EXCEPT
    • PostgreSQL Roles
    • PostgreSQL Link
    • PostgreSQL Partition
    • PostgreSQL column does not exist
    • PostgreSQL Log Queries
    • PostgreSQL escape single quote
    • PostgreSQL Query Optimization
    • PostgreSQL Character Varying
    • PostgreSQL Transaction
    • PostgreSQL Extensions
    • PostgreSQL Import CSV
    • PostgreSQL Client
    • PostgreSQL caching
    • PostgreSQL Incremental Backup
    • PostgreSQL JSON vs JSONNB
    • PostgreSQL JDBC Driver
    • PostgreSQL Interview Questions

PostgreSQL Operators

By Priya PedamkarPriya Pedamkar

PostgreSQL Operators

Introduction to PostgreSQL Operators

PostgreSQL Operators is a database management system and open-source software that enables easy access for the public to use for relational database purposes. Relational Database purposes are actually the manageability of data to explain it in a nutshell.

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,112 ratings)

PostgreSQL Operators

Below are the different PostgreSQL Operators, which are as follows:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

1. Logical Operators

In PostgreSQL, the logical operators consist of the general operators, namely, In PostgreSQL, logical operators are used to performing the logical operations as described below.

  • OR
  • AND
  • NOT
a. OR Operator
OR The operator returns TRUE if either value of an operand is TRUE.
  • Values passed as logic can be applied in different combinations to gain desired results.
  • So let us look at the truth table below.
  • We can assume 0 as FALSE and 1 as TRUE. Hence 0 or 1 is 1, which is essentially TRUE.
  • We can see that the OR operator returns FALSE (0) only when both X and Y are FALSE.

X

Y

X OR Y

0

0 0

0

1

1

1

0

1

1 1

1

b. AND Operator
AND The operator returns TRUE only if the values of all operands are TRUE.
  • Unlike the OR operator, AND operator returns TRUE (1) only when both X and Y are TRUE.

X

Y

X AND Y

0

0

0

0

1

0

1

0

0

1

1 1
c. NOT Operator
NOT This operator negates the initial value of an operand. If the operand value is TRUE, then FALSE is returned.

Regarding the NOT operator, the logic is that the operator returns FALSE if the operand is TRUE and vice versa.

X

NOT(X)

0

1
1

0

2. Arithmetic Operators/Mathematical Operators

Arithmetic operators perform a specific mathematical operation like addition, subtraction, etc. In PostgreSQL, Arithmetic operators are used to performing the Arithmetic operations as described below.

Operator Name

Operators

Functionality

Example

Result

Addition

+

Adds values of operands 10 +11 21
Subtraction

–

Subtracts values of operands 10 -11 -1
Multiplication

*

Performs multiplication on operands 10 * 11 110
Division

/

Performs Division on operands 10/5 2
Modulo

%

Performs Division but returns the remainder as output 11%10 1
Exponentiation

^

This provides the power value of the desired operand 10^2 100
Square Root

| /

Performs Square Root of an operand |/ 16 4
Cube Root

| | /

Performs Cube root of an operand ||/64 4
Factorial

!

Returns factorial of a given number (Postfix form) 4! 24
Factorial ( with prefix operator)

!!

Returns factorial of a given number (Prefix form) !! 4 24

3. Bitwise Operators

To understand Bitwise operators’ functionality, we need to understand that these operators will work only on integrals, and the functionality of the operator actually takes place in the binary form (representation in 0s and 1s) of the operand. In PostgreSQL, Bitwise operators are used to performing the Bitwise operators as described below.

Operator Name

Operators Example

Result

Bitwise AND

&

10 & 12 8
Bitwise OR

|

10 | 12 14
Bitwise NOT

~

~10 5
Bitwise XOR

#

10 # 12 6
Bitwise shift left

<<

10 << 2 40
Bitwise shift right

>>

100 >> 2 25

Let us take two operands, for example:

  • 10 – Binary Representation is 1010.
  • 12 – Binary Representation is 1100.

Refer below to how operands 10 and 12 get interpreted into their equivalent Binary form.

10 – Binary Representation is 1010

 Bitwise operator

12 – Binary Representation is 1100

Bitwise operators 2

a. Bitwise AND Operator

This operator interprets the operands in their binary representation and performs the AND function to every digit of the operands.

Bitwise AND

b. Bitwise OR Operator

This operator interprets the operands in their binary representation and performs the OR function to every digit of the operands.

 Bitwise OR

c. Bitwise Not Operator

This operator performs the negation operation on each digit of the operand. It can take only one operand at a time; hence it is known as a unary operator.

Bitwise Not

In the above example, all 0S are converted to 1S and vice versa.

d. Bitwise XOR Operator

This operator interprets the operands in their binary representation and performs the XOR function to every digit of the operands.

  • XOR function returns TRUE or 1 if either one of the operands is TRUE or 1
  • XOR function returns FALSE or 0 if all the operands are TRUE or all the operands are FALSE.

Bitwise XOR

e. Bitwise Shift Left Operator

This operator shifts the given number’s bits in its binary representation to the left side by a specified number of bits. Let us say the specified number of bits is x, then shift each bit of 10 to the left by x bits is denoted as 10 <<x. If x is 2 then 10 << 2 is 40.

Shift Left

f. Bitwise Shift Right Operator

This operator shifts the bits of the given number in binary representation to the right side by a specified number of bits. Let us say the specified number of bits is x, then shift each bit of 10 to the right by x bits is denoted as 10 <<x.If x is 2 then 10 >> 2 is 25.

Shift Right

4. Comparison Operators

Comparison Operators are operators that interpret an expression and provide output in Boolean values. (TRUE or FALSE). In PostgreSQL, Comparison Operators are used to performing the Comparison Operators as described below.

Some of the common Comparison operators are shown below. 

Operator

Operator Name

<

Less than an operator

>

Greater than operator

=

Equals

<> or! =

not equals

<=

Less than or equal to operator

>=

Greater than or equal to operator
a. Operator ‘<.’

This operator compares the given expression and returns TRUE if the first operand is less than the second operand in the expression, or else it returns FALSE.

 Comparison operators

b. Operator ‘>.’

This operator compares the given expression and returns TRUE if the first operand is greater than the second operand in the expression, or else it returns FALSE.

Comparison operators

c. Operator ‘=.’

This operator compares the operands in the expression and returns TRUE if both operands are of the same value or else it returns FALSE.

Comparison operators 3

d. Operator ‘<>’ and ‘!=.’

This operator compares the operands in the expression and returns TRUE if both operands are not of the same value or return FALSE.

Comparison operators 4

e. Operator ‘ <=.’

This operator returns TRUE if the first operand’s value is lesser or equal to the value of the second operand.

Comparison operators 5

f. Operator ‘>=.’

This operator returns TRUE if the first operand’s value is greater or equal to the value of the second operand.

 Comparison operators 6

Recommended Articles

This has been a guide to PostgreSQL Operators. We discuss different types of PostgreSQL Operators like Arithmetic Operators, Comparison Operators, and Logical Operators, Bitwise operators with examples. You may also look at the following articles to learn more –

  1. MySQL Operators
  2. Oracle and PostgreSQL
  3. SQL Server vs PostgreSQL
  4. PostgreSQL Versions with Features
Popular Course in this category
SQL Training Program (7 Courses, 8+ Projects)
  7 Online Courses |  8 Hands-on Projects |  73+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more