2024-09-08 01:58:27 +02:00
# Postgres Cheatsheet
### Enter command-line
```
su postgres -c psql
```
### Connect to database
```
\c [db]
```
### List columns in table
```
\d+ [t]
```
### Create database
```
CREATE DATABASE [name];
```
### Create user
```
CREATE USER [name] WITH PASSWORD 'xxx';
```
### Grant all privileges for user to database
```
GRANT ALL PRIVILEGES ON DATABASE [db] TO [user];
```
### Change ownership of database
```
ALTER DATABASE [db] OWNER TO [user];
```
### Show all tables in schema
```
\dt
```
2024-09-08 02:02:01 +02:00
### Show all data in table
```
SELECT * from [table];
```
### Change field in entry
```
UPDATE [table] SET password = 123 WHERE username = hexlocation;
```
2024-09-08 01:58:27 +02:00
## Troubleshooting
### Reserved Keywords
Postgres might complain about an argument being invalid syntax when passing a reserved keyword as argument. Try enclosing the argument in quotation marks.