Sometimes, as developers, we need to share query results with teammates maybe to explain a bug, show app behavior, or provide visibility into some data. Often, this means copying directly from the terminal.
But here’s the catch: 😕
Pasting raw SQL output into a text editor or a spreadsheet usually ends in a chaos 😫😤😞. Everything dumped into a single cell, broken formatting, unreadable messes 🥴.
And yet, putting this data into Google Sheets is super helpful: it’s clear, searchable, and collaborative. But exporting to CSV just for that? Too much friction.
Here’s a dead-simple way to copy query results from psql and paste them cleanly into Google Sheets—no CSVs, no cleanup, no formatting pain.
🔧 How to do it (in seconds):
1. Open your terminal and start psql
:
psql -U your_user -d your_database
2. Set output to tab-separated format (what Google Sheets understands natively):
\x off
\pset format unaligned
\pset fieldsep '\t'
3. Run your query:
SELECT id, name, email FROM users LIMIT 10;
4. Copy the result from your terminal and paste it directly into Google Sheets.
😲 Each column goes perfectly into its own cell
😄 Each row drops nicely into a separate row
😌 No cleaning, no reformatting, just pure copy/paste joy
No CSV. No cleaning. No pain.
Hope this saves you time!
If it did, give it a 💚 or share it with your team.
Top comments (0)