DEV Community

Brady Holt
Brady Holt

Posted on • Originally published at geekytidbits.com on

1 2

TIL: psql with VSCode

I was catching up on my Feedly yesterday and ran across Postgres Hidden Gems by Craig Kerstein. There are some really neat things in that list! One thing that caught my eye was this one:

@l_avrot – The fact that we can use vim editor in psql

Really? I didn’t know that. Tell me more. So I Googled a bit and of course another post from Craig titled How I Work With Postgres – Psql, My PostgreSQL Admin popped up. Here, he explains how to use \e in psql to “allow you to view and edit your last run query in your editor of choice”. That sounds really useful, especially when working with longer, more involved queries.

My “editor of choice” is VSCode and when I attempted to use \e with my EDITOR var set to “code” it did not work. The current query was not passed to VSCode and when saving the file from VSCode, nothing got sent back to psql.

More Googling and fiddling and I found that I needed to add the -w parameter when launching VSCode so that it would “Wait for the files to be closed before returning.”, per the --help output. Also, I learned that you can use PSQL_EDITOR to set the editor specific to psql, which I prefer because I like keeping EDITOR set to vim for varios shell things. Editing SQL, however, I would much prefer to do in VSCode rather than vim, thank you very much. So, now I have the following environment variable defined in my .zshrc:

export PSQL_EDITOR="code -w"
Enter fullscreen mode Exit fullscreen mode

Now when I enter \e from psql, VSCode launches with the contents of my current or last executed query and saving the file results in psql executing the query. Awesome!

Image of AssemblyAI tool

Transforming Interviews into Publishable Stories with AssemblyAI

Insightview is a modern web application that streamlines the interview workflow for journalists. By leveraging AssemblyAI's LeMUR and Universal-2 technology, it transforms raw interview recordings into structured, actionable content, dramatically reducing the time from recording to publication.

Key Features:
🎥 Audio/video file upload with real-time preview
🗣️ Advanced transcription with speaker identification
⭐ Automatic highlight extraction of key moments
✍️ AI-powered article draft generation
📤 Export interview's subtitles in VTT format

Read full post

Top comments (1)

Collapse
 
andy profile image
Andy Zhao (he/him)

Woah, cool! Makes editing SQL much easier to look at.

Billboard image

Try REST API Generation for MS SQL Server.

DreamFactory generates live REST APIs from database schemas with standardized endpoints for tables, views, and procedures in OpenAPI format. We support on-prem deployment with firewall security and include RBAC for secure, granular security controls.

See more!

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay