PostgreSQL Fundamentals
Go deep into POSTGRESQL with relational modeling, advanced SQL, JSONB, arrays, indexing, full-text search.
01Introduction to PostgreSQLWhat is PostgreSQL? PostgreSQL (often called Postgres ) is a powerful, open-source object-relational database system. It has over 35. ACID Compliant — Guarantees data integrity Extensible — Custom types, functions, operators -- Using psql command-lincodequizbeginner
What is PostgreSQL? PostgreSQL (often called Postgres ) is a powerful, open-source object-relational database system. It has over 35. ACID Compliant — Guarantees data integrity Extensible — Custom types, functions, operators -- Using psql command-lin
-- Using psql command-line tool
psql -U postgres -d mydb
-- Connection string format
postgresql://user:password@host:5432/database
-- Common psql meta-commands
l -- list databases
c mydb -- connect to database
dt -- list tables
d table -- describe table
q -- quitWhat does ACID stand for in database terminology?
Which PostgreSQL data type stores JSON in binary format with indexing support?
Which psql command lists all databases?
02SELECT StatementThe SELECT Statement SELECT retrieves data from one or more tables. PostgreSQL's SELECT is very powerful with many optional. SELECT column1, column2, ... FROM table_name [WHERE condition] [GROUP BY columns] [HAVING condition] [ORDER BY columns] [LIMIcodequizbeginner
The SELECT Statement SELECT retrieves data from one or more tables. PostgreSQL's SELECT is very powerful with many optional. SELECT column1, column2, ... FROM table_name [WHERE condition] [GROUP BY columns] [HAVING condition] [ORDER BY columns] [LIMI
SELECT column1, column2, ...
FROM table_name
[WHERE condition]
[GROUP BY columns]
[HAVING condition]
[ORDER BY columns]
[LIMIT count]
[OFFSET skip];Which clause removes duplicate rows from query results?
What keyword creates a column alias?
What does SELECT * return?
03WHERE & FilteringWHERE Clause The WHERE clause filters rows based on conditions. PostgreSQL supports rich comparison and logical operators. SELECT * FROM employees WHERE salary > 70000; SELECT * FROM employees WHERE department = 'Engineering'; SELECT * FROM employeescodequizbeginner
WHERE Clause The WHERE clause filters rows based on conditions. PostgreSQL supports rich comparison and logical operators. SELECT * FROM employees WHERE salary > 70000; SELECT * FROM employees WHERE department = 'Engineering'; SELECT * FROM employees
SELECT * FROM employees WHERE salary > 70000;
SELECT * FROM employees WHERE department = 'Engineering';
SELECT * FROM employees WHERE hire_date >= '2022-01-01';
SELECT * FROM employees WHERE status != 'inactive'; -- or <>Which PostgreSQL-specific LIKE variant is case-insensitive?
SELECT * FROM t WHERE x BETWEEN 10 AND 20 — is 10 included?
How do you check if a column has no value in PostgreSQL?
04ORDER BY & LIMITORDER BY — Sorting Results ORDER BY sorts query results. You can sort by one or multiple columns, ascending or descending. -- Ascending (default) SELECT * FROM employees ORDER BY last_name; SELECT * FROM employees ORDER BY last_name ASC; -- Descendincodequizbeginner
ORDER BY — Sorting Results ORDER BY sorts query results. You can sort by one or multiple columns, ascending or descending. -- Ascending (default) SELECT * FROM employees ORDER BY last_name; SELECT * FROM employees ORDER BY last_name ASC; -- Descendin
-- Ascending (default)
SELECT * FROM employees ORDER BY last_name;
SELECT * FROM employees ORDER BY last_name ASC;
-- Descending
SELECT * FROM employees ORDER BY salary DESC;
-- Multiple columns
SELECT * FROM employees
ORDER BY department ASC, salary DESC;What is the default sort order in ORDER BY?
To get items 11-20, what LIMIT/OFFSET should you use?
Which keyword controls NULL position in ORDER BY in PostgreSQL?