public inbox for [email protected]
help / color / mirror / Atom feedFrom: Corey Huinker <[email protected]>
To: Denis Gantsev <[email protected]>
Cc: Tom Lane <[email protected]>
Cc: [email protected]
Subject: Re: Feature proposal for psql
Date: Sat, 19 Sep 2020 19:25:37 -0400
Message-ID: <CADkLM=em8EEJgJ+Do1i_ykuDw5YCU7v80FqaFFwdg0L0ddt8WA@mail.gmail.com> (raw)
In-Reply-To: <CAPsvASv2ZRq4ZTZQAvwzAh4CnfK=6+0H-iFRaopCo-NA3aFoWA@mail.gmail.com>
References: <CAPsvASuWxEuqW-x73_x4-Mgj7i3P9LgHRcn4UQpxUriBVqguqA@mail.gmail.com>
<[email protected]>
<CAPsvASv2ZRq4ZTZQAvwzAh4CnfK=6+0H-iFRaopCo-NA3aFoWA@mail.gmail.com>
>> One limitation of this approach is that \set can't span lines, so
>> writing complex queries would be kinda painful. But that would
>> be a good limitation to address separately; \set isn't the only
>> metacommand where can't-span-lines is a problem sometimes.
>> If you seriously want to pursue adding a feature like this,
>> probably the -hackers list is a more appropriate discussion
>> forum than -novice.
>>
>> regards, tom lane
>>
>
> The ability to save and retrieve multi-line queries would be quite nice
> though, often I would like to save a query too large to type.
>
> I think I don't know psql well enough to propose a viable syntax, so I
> guess that would be up to experts here...
> But I would be pretty happy to implement it.
>
> Regards
> Denis
>
>
Well, if you want to do it right now, you can do this:
db=> select * from foo;
x | y
----+----
1 | 1
2 | 2
3 | 3
4 | 4
5 | 5
6 | 6
7 | 7
8 | 8
9 | 9
10 | 10
(10 rows)
db=> select * from foo where x = :xval \w query1.sql
db=> \set xval 4
db=> \i query1.sql
x | y
---+---
4 | 4
(1 row)
Granted, that involves adding files to the filesystem, setting variables
rather than passing parameters, remembering what those variables were, and
having the discipline to not have overlapping uses for variable names
across multiple files.
So the key shortcomings right now seem to be:
* no way to pass in values to an \i or \ir and no way to locally scope them
* one file per query
Setting variables locally in a \ir would need to somehow push and pop
existing variable values because those vars are scoped at the session
level, and that might confuse the user when they set the var inside the
included file expecting the calling session to keep the value.
Perhaps we could add a notion of a "bag of tricks" dir in each user's home
directory, and a slash command \wbag (better name suggestions welcome) that
behaves like \w but assumes the file will go in ~/.psql-bag-of-tricks/ and
\ibag which includes a file from the same dir.
view thread (4+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: Re: Feature proposal for psql
In-Reply-To: <CADkLM=em8EEJgJ+Do1i_ykuDw5YCU7v80FqaFFwdg0L0ddt8WA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox