Skip to content

Instantly share code, notes, and snippets.

@lucasscariot
Last active December 6, 2017 10:27
Show Gist options
  • Save lucasscariot/1c7d4ac883f968dba94f55d5c946a3c3 to your computer and use it in GitHub Desktop.
Save lucasscariot/1c7d4ac883f968dba94f55d5c946a3c3 to your computer and use it in GitHub Desktop.
Cheat sheet for Postgresql command line.

Output Formating

Command Info
\a Toggle aligned/unaligned rows (default aligned)
\x Toggle expanded output (default off)
\H Toggle html output (default off)
\t Show only rows (default off)

Database Navigation

Command Info
\l List all databases
\d Describe table (Print table structure)
\du List users
\q Quit psql

Record Listing

Command Info
SELECT * FROM users ORDER BY id DESC LIMIT 20; List with limit
SELECT * FROM "userProject" ORDER BY id DESC LIMIT 20; Double quote for camelCase with postgres

Files

Command Info
\i Execute commands from file
\o Send all query results to file or
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment