Skip to content

Instantly share code, notes, and snippets.

@nepsilon
Last active February 19, 2017 13:19
Show Gist options
  • Save nepsilon/9ecc91e2dd9c0bbfd134 to your computer and use it in GitHub Desktop.
Save nepsilon/9ecc91e2dd9c0bbfd134 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