Feature proposal for psql

From: Denis Gantsev <gantsevdenis(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Feature proposal for psql
Date: 2020-09-19 14:53:24
Message-ID: CAPsvASuWxEuqW-x73_x4-Mgj7i3P9LgHRcn4UQpxUriBVqguqA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-novice

Hello
I have a working proposal for a small feature, which I would describe in
one sentence as
"named parametrized queries".
Basically it allows to save something like this in a file:

--psql:MyQuery1
SELECT 42 FROM @0
WHERE true
--psql:end

--psql:MyQuery2
/* updates stuff... */
UPDATE stuff SET ..
--psql:end

Then, from inside psql, I can invoke the query by its name, and pass an (or
many) argument(s).
For example, invoking it like so:
db=# \nq MyQuery1 blabla
Would substitute literally the "@0" with "blabla" and send it to the
backend.

I am aware that saving queries is already possible with variables (:var),
and saved variables can be sourced from .psqlrc file.
However, I think passing arguments in bash style is kinda nicer, because I
don't need to set any variables beforehand. Also this would allow to have a
clean and valid SQL (well kinda, if no placeholders "@" is used) and
comments.
I have also added autocompletion.

Should I send the diff to the mailing list, or maybe it's not something
useful?

Regards
Denis

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Justin Pryzby 2020-09-19 16:00:31 Re: please update ps display for recovery checkpoint
Previous Message Tom Lane 2020-09-19 14:52:50 Re: recovering from "found xmin ... from before relfrozenxid ..."

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2020-09-19 17:20:34 Re: Feature proposal for psql
Previous Message Laurenz Albe 2020-09-18 15:09:08 Re: New Data Type Implementation