Catalog / PostgreSQL Cheat Sheet
PostgreSQL Cheat Sheet
A quick reference guide to PostgreSQL, covering essential commands, data types, functions, and syntax for database management and querying.
Basic Commands & Syntax
Connecting & Creating Databases
|
Connect to a PostgreSQL database. |
|
Create a new database. |
|
List all databases. |
|
Connect to a specific database. |
|
Delete a database. |
|
List tables in the current database. |
Basic SQL Commands
|
Retrieve data from a table. |
|
Insert new data into a table. |
|
Modify existing data in a table. |
|
Remove data from a table. |
|
Create a new table. |
|
Delete a table. |
Data Types
Numeric: |
Character: |
Date/Time: |
Boolean: |
Other: |
Advanced Querying
Filtering and Sorting
|
Filter rows based on a condition. |
|
Sort the result set by a column in ascending or descending order. |
|
Limit the number of rows returned. |
|
Skip the first n rows. |
|
Pattern matching ( |
|
Case-insensitive pattern matching. |
Joins
|
Returns rows only when there is a match in both tables. |
|
Returns all rows from table1 and matching rows from table2. If no match, |
|
Returns all rows from table2 and matching rows from table1. If no match, |
|
Returns all rows when there is a match in one of the tables. |
|
Returns the Cartesian product of the tables. |
Aggregate Functions
|
|
|
|
|
|
|
Transactions & Concurrency
Transactions
|
Starts a transaction block. |
|
Saves the changes made during the transaction. |
|
Discards the changes made during the transaction. |
|
Sets a savepoint within a transaction. |
|
Rolls back to a specific savepoint. |
Concurrency Control
Isolation Levels: |
|
|
Lock Modes: |
Functions & Operators
String Functions
|
Returns the length of the string. |
|
Converts the string to uppercase. |
|
Converts the string to lowercase. |
|
Removes leading and trailing spaces. |
|
Extracts a substring from the string. |
|
Replaces occurrences of |
Date/Time Functions
|
Returns the current timestamp. |
|
Returns the current date. |
|
Returns the current time. |
|
Extracts a field (e.g., year, month, day) from a timestamp. |
|
Truncates a timestamp to a specified field. |
Operators
Comparison: |
Logical: |
String Concatenation: |
Mathematical: |
Pattern Matching: |