Feature proposal for psql - Mailing list pgsql-novice

From Denis Gantsev
Subject Feature proposal for psql
Date
Msg-id CAPsvASuWxEuqW-x73_x4-Mgj7i3P9LgHRcn4UQpxUriBVqguqA@mail.gmail.com
Whole thread Raw
Responses Re: Feature proposal for psql
List 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

pgsql-novice by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: New Data Type Implementation
Next
From: Tom Lane
Date:
Subject: Re: Feature proposal for psql