Postgres cheatsheet
PostgreSQL commands
|
Access the PostgreSQL server from psql with a specific user |
|
Connect to a specific database |
|
Quit the psql |
|
List all databases in the PostgreSQL database server |
|
List all schemas |
|
List all stored procedures and functions |
|
List all views |
|
Lists all tables in the current database |
|
Get more information on tables in the current database |
|
Get detailed information on a table |
|
Show a stored procedure or function code |
|
Show query output in the pretty-format |
|
List all users |
|
Create a new role |
|
Create a new role with a username and password |
|
Change role to the |
|
Allow |
Managing databases
|
Create a new database |
|
Delete a database permanently |
Managing tables
|
Create a new table or a temporary table |
|
Add a new column to a table |
|
Drop a column in a table |
|
Rename a column |
|
Set or remove a default value for a column |
|
Add a primary key to a table |
|
Remove the primary key from a table |
|
Rename a table |
|
Drop a table and its dependent objects |
Managing views
|
Create a view |
|
Create a recursive view |
|
Create a materialized view |
|
Refresh a materialized view |
|
Drop a view |
|
Drop a materialized view |
|
Rename a view |
Managing indexes
|
Create an index with the specified name on a table |
|
Remove a specified index from a table |
Querying data from tables
|
Query all data from a table |
|
Query data from the specified columns of all rows in a table |
|
Query data and select only unique rows |
|
Query data from a table with a filter |
|
Assign an alias to a column in the result set |
|
Query data using the |
|
Query data using the |
|
Query data using the |
|
Constrain the returned rows with the |
|
Query data from multiple tables using the inner join |
|
Return the number of table rows |
|
Sort rows in ascending or descending order |
|
Group rows using the |
|
Filter groups using the |
Set operations
|
Combine the result set of two or more queries with the |
|
Minus a result set using the |
|
Get intersection of the result sets of two queries |
Modifying data
|
Insert a new row into a table |
|
Insert multiple rows into a table |
|
Update data for all rows |
|
Update data for the set of rows specified by the condition in the |
|
Delete all rows of a table |
|
Delete specific rows based on a condition |