cheatsheets/postgres/postgres.md
hexlocation 7a9ddb910b yes
2024-09-08 02:02:01 +02:00

936 B

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

Show all data in table

SELECT * from [table];

Change field in entry

UPDATE [table] SET password = 123 WHERE username = hexlocation;

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.