Skip to content

Instantly share code, notes, and snippets.

@t0mab
Forked from nepsilon/3-postgres-tips.md
Created October 17, 2016 15:12
Show Gist options
  • Save t0mab/ffca662602b26c5192059f1d9b35b009 to your computer and use it in GitHub Desktop.
Save t0mab/ffca662602b26c5192059f1d9b35b009 to your computer and use it in GitHub Desktop.
3 tips for a better PostgreSQL usage — First published in fullweb.io issue #38

3 tips for a better PostgreSQL usage

We’ll see how to write queries in your editor, format output based on content and how to get info on everything.

1. Use your editor to write queries:

Tell the terminal what editory to use with from your bash shell export EDITOR=subl, then in psql type:

psql> \e

It will open SublimeText with the last query. Close the file and the query will run.

2. Turn too long columns into lines:

psql> \x auto

Postgres will then use the most intelligible way to display the records.

3. Use \d to get info on anything:

Info about current database:

psql> \d

More info about current database:

psql> \d+

Info about a table:

psql> \d t_table_name

Info about functions:

psql> \df

See about the 39 other \d commands with:

psql> \?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment