
- PostgreSQL - Home
- PostgreSQL - Overview
- PostgreSQL - Environment Setup
- PostgreSQL - Syntax
- PostgreSQL - Data Types
- PostgreSQL - Operators
- PostgreSQL - Expressions
- PostgreSQL Database
- PostgreSQL - Create Database
- PostgreSQL - ALTER DATABASE
- PostgreSQL - Drop Database
- PostgreSQL - Loading Database
- PostgreSQL - Rename Database
- PostgreSQL - Select Database
- PostgreSQL - Show Database
- PostgreSQL Query Operations
- PostgreSQL - SELECT
- PostgreSQL - CREATE
- PostgreSQL - INSERT
- PostgreSQL - UPDATE
- PostgreSQL - DELETE
- PostgreSQL - ALTER TABLE Command
- PostgreSQL - WHERE Clause
- PostgreSQL - ORDER BY Clause
- PostgreSQL - GROUP BY
- PostgreSQL - HAVING Clause
- PostgreSQL - DISTINCT Keyword
- PostgreSQL - LIMIT Clause
- PostgreSQL - LIKE Clause
- PostgreSQL - WITH Clause
- PostgreSQL - AND & OR Clauses
- PostgreSQL - DROP TABLE
- PostgreSQL - Upsert
- TRUNCATE TABLE Command
- PostgreSQL JOINS & Schemas
- PostgreSQL Schemas
- PostgreSQL Joins
- PostgreSQL Data Integrity & Transaction
- PostgreSQL - Constraints
- PostgreSQL - Transactions
- PostgreSQL - Commit
- PostgreSQL - Rollback
- PostgreSQL - Views
- PostgreSQL Functions
- PostgreSQL - ALIAS Syntax
- PostgreSQL - Functions
- PostgreSQL - Useful Function
- PostgreSQL - MAX() Function
- PostgreSQL - MIN() Function
- PostgreSQL - SUM() Function
- PostgreSQL - COUNT() Function
- PostgreSQL - Array Function
- PostgreSQL - String Function
- PostgreSQL - Numeric Function
- PostgreSQL Operators
- PostgreSQL - UNION Operator
- PostgreSQL - INTERSECT Operator
- PostgreSQL - EXCEPT Operator
- PostgreSQL - ANY Operator
- PostgreSQL - ALL Operator
- PostgreSQL - EXISTS Operator
- PostgreSQL Interface
- PostgreSQL - C / C++
- PostgreSQL - Java
- PostgreSQL - PHP
- PostgreSQL - Perl
- PostgreSQL - Python
- Advanced PostgreSQL
- PostgreSQL - NULL Values
- PostgreSQL - Triggers
- PostgreSQL - Indexes
- PostgreSQL - Locks
- PostgreSQL - Sub Queries
- PostgreSQL - Auto Increment
- PostgreSQL - Privileges
- PostgreSQL - Date/Time Functions & Operators
- PostgreSQL - Errors & Messages
- PostgreSQL - Assert
PostgreSQL ALL Operator
The ALL operator in PostgreSQL compares a value against all elements of an array. This operator is used to checks the strict condition. For example, consider a hiring process where a candidates scores must be above a certain level. Then use the ALL operator to filter the strong candidates.
Syntax
Following is the syntax of ALL operators in PostgreSQL −
expression operator ALL (array | subquery)
Here,
- "expression" is the value to compare, operator is a comparison sign (=, <, >, <=, >=, <>), and array contains multiple values.
Example of ALL Operator in PostgreSQL
Here, we create one table name of students which stores the records of rows and columns. Our target is only to filter strong candidates.
Step 1: Start with CREATE TABLE and the put the values using INSERT INTO.
CREATE TABLE students ( id SERIAL PRIMARY KEY, name TEXT, age INT, experience INT, skills TEXT[], scores INT[] ); INSERT INTO students (name, age, experience, skills, scores) VALUES ('Radha', 28, 5, ARRAY['Python', 'SQL'], ARRAY[85, 90, 95]), ('Sarika', 32, 7, ARRAY['Java', 'PostgreSQL'], ARRAY[88, 92, 99]), ('Revathi', 24, 2, ARRAY['Go', 'SQL'], ARRAY[60, 75, 80]), ('Raman', 30, 6, ARRAY['C++', 'Python'], ARRAY[70, 85, 88]), ('Akshita', 27, 4, ARRAY['Swift', 'SQL'], ARRAY[55, 65, 70]), ('Farhan', 35, 10, ARRAY['Ruby', 'JavaScript'], ARRAY[95, 98, 100]);
Step 2: Use the ALL Operator to filter the result.
Query I: Find students whose all scores are greater than 80.
SELECT name, scores FROM candidates WHERE 80 < ALL (scores);
The first query produces the following result −
name | scores |
---|---|
Radha | {85,90,95} |
Sarika | {88,92,99} |
Farhan | {95,98,100} |
Query II: Find students who have all scores greater than or equal to 90.
SELECT name FROM candidates WHERE 90 <= ALL (scores);
The second query produces the following result −
name |
---|
Farhan |