DEV Community

Michel Sánchez Montells
Michel Sánchez Montells

Posted on

Copy & Paste PostgreSQL Query Results into Google Sheets (No CSV Needed)

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
Enter fullscreen mode Exit fullscreen mode

2. Set output to tab-separated format (what Google Sheets understands natively):

\x off
\pset format unaligned
\pset fieldsep '\t'
Enter fullscreen mode Exit fullscreen mode

3. Run your query:

SELECT id, name, email FROM users LIMIT 10;
Enter fullscreen mode Exit fullscreen mode

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)