Tuesday, November 10, 2015

PostgreSQL Cheat Sheet



Open command line

sudo -u postgres psql


Quit command line

\q

Get the current user

SELECT CURRENT_USER;

List databases

\l

Connect to a database

\c dbname

List tables in a database

\dt

List columns of a table

\d tablename

Export the sql result to a CSV

Copy (Select * From tablename) To '/tmp/result.csv' With CSV;

Limit the sql result

select * from tablename limit 10;

Work with JSONB type

No comments:

Post a Comment