PostgreSQL
Compare with MySQL/MariaDB
Command | MySQL/MariaDB | PostgreSQL |
List Tables | LIST TABLES | \dt |
Show Comlums | DESC {table} | \d {table} |
Autoincrement | {column} SERIAL PRIMARY KEY, | {column} INT AUTO_INCREMENT, PRIMARY KEY ({column}) |
PostgreSQL in Docker
Open psql
in Docer
docker exec -ti CONTAINER psql DB USER
Example
docker exec -ti wordpress-db psql wordpress wordpress
With Undo
If you enter commands direct into psql
,
you can wrap them with a transaction.
After opening psql
,
start the transaction.
BEGIN;
Then enter your commands. You can see the effect, but it will be limited to your session.
If you were successful and want to keep it, commit the transaction.
COMMIT;
Or, if you made a mistake or something didn't work as expected, you can rollback the transaction.
ROLLBACK;