# Simple but handy Postgres features

DevFeed: [Simple but handy Postgres features](<https://devfeed.tech/articles/simple-but-handy-postgres-features-41193.md>)

Original publisher: [Read original article](<https://www.craigkerstiens.com/2017/01/08/simple-but-handy-postgresql-features/>)

Author: Map

Published: 2017-01-08T20:55:56Z

Content type: tutorial

Language: en

Sources: [Craig Kerstiens](<https://devfeed.tech/sources/craig-kerstiens.md>)

Topics: [data](<https://devfeed.tech/topics/data.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [Terminal](<https://devfeed.tech/topics/terminal.md>), [JSON](<https://devfeed.tech/topics/json.md>), [real-time](<https://devfeed.tech/topics/real-time.md>), [Vim](<https://devfeed.tech/topics/vim.md>), [Emacs](<https://devfeed.tech/topics/emacs.md>), [CSV](<https://devfeed.tech/topics/csv.md>), [Sublime Text](<https://devfeed.tech/topics/sublime-text.md>), [dashboards](<https://devfeed.tech/topics/dashboards.md>)

Tags: [cli](<https://devfeed.tech/tags/cli.md>), [command](<https://devfeed.tech/tags/command.md>), [csv](<https://devfeed.tech/tags/csv.md>), [dashboard](<https://devfeed.tech/tags/dashboard.md>), [data](<https://devfeed.tech/tags/data.md>), [debugging](<https://devfeed.tech/tags/debugging.md>), [editor](<https://devfeed.tech/tags/editor.md>), [emacs](<https://devfeed.tech/tags/emacs.md>), [google](<https://devfeed.tech/tags/google.md>), [json](<https://devfeed.tech/tags/json.md>), [jsonb](<https://devfeed.tech/tags/jsonb.md>), [postgres](<https://devfeed.tech/tags/postgres.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [query](<https://devfeed.tech/tags/query.md>)

## AI overview

A practical guide to useful PostgreSQL features, including editing and rerunning queries from psql, monitoring changing query results with \watch, pretty-printing JSONB, and importing query results into Google Sheets.

## Source excerpt

It seems each week when I'm reviewing data with someone a feature comes up that they had no idea existed within Postgres. In an effort to continue documenting many of the features and functionality that are useful, here's a list of just a few that you may find handy the next time your working with your data. Psql, and \e This one I've covered before, but it's worth restating. Psql is a great editor that already comes with Postgres. If you're comfortable on the CLI you should consider giving it a try. You can even setup you're own .psqlrc for it so that it's well customized to your liking. In particular turning \timing on is especially useful. But even with all sorts of customization if you're not aware that you can use your preferred editor by using \e then you're missing out. This will allow you to open up the last run query, edit it, save-and then it'll run for you. Vim, Emacs, even Sublime text works just take your pick by setting your $EDITOR variable. Watch Ever sit at a terminal running a query over and over to see if something on your system changed? If you're debugging something whether locally or even live in production, watching data change can be key to figuring out. Instead of re-running your query you could simply use the \watch command in Postgres, this will re-run your query automatically every few seconds. SELECT now() - query_start, state, query FROM pg_stat_activity \watch JSONB pretty print I love JSONB as a datatype. Yes, in cases it won't be the optimal for performance (though at times it can be perfectly fine). If I'm hitting some API that returns a ton of data, I'm usually not using all of it right away. But, you never know when you'll want to use the rest of it. I use Clearbit this way today, and for safety sake I save all the JSON result instead of de-normalizing it. Unfortunately, when you query this in Postgres you get one giant compressed text of JSON. Yes, you could pipe out to something like jq, or you could simply use Postgres built in