Обсуждение: [PATCH] psql \n shortcut for set search_path =
Hi,
Attached please find a trivial patch for psql which adds a \n meta command as a shortcut for typing set search_path =.
This allows you to use psql as follows:
\dn
\n my_schema
\d
\d my_table
etc.
Not yet done: updating documentation (psql internal help, psql man page, main documentation).
If this is something that is desired (I hope so as this is something I now use a lot), I will update the documentation and resubmit.
Cheers,
Colin
Attached please find a trivial patch for psql which adds a \n meta command as a shortcut for typing set search_path =.
This allows you to use psql as follows:
\dn
\n my_schema
\d
\d my_table
etc.
Not yet done: updating documentation (psql internal help, psql man page, main documentation).
If this is something that is desired (I hope so as this is something I now use a lot), I will update the documentation and resubmit.
Cheers,
Colin
Вложения
On Tue, Jul 10, 2012 at 2:09 AM, Colin 't Hart <colin@sharpheart.org> wrote: > Attached please find a trivial patch for psql which adds a \n meta command > as a shortcut for typing set search_path =. I think the use-case is a bit narrow: saving a few characters typing on a command not everyone uses very often (I don't), at the expense of adding yet another command to remember. Plus it opens the floodgates to people wanting yet more separate commands for other possibly commonly-used SET commands. There are a lot of GUCs, after all, even counting only those changeable at runtime. Josh
Josh Kupershmidt <schmiddy@gmail.com> writes: > On Tue, Jul 10, 2012 at 2:09 AM, Colin 't Hart <colin@sharpheart.org> wrote: >> Attached please find a trivial patch for psql which adds a \n meta command >> as a shortcut for typing set search_path =. > I think the use-case is a bit narrow: saving a few characters typing > on a command not everyone uses very often (I don't), at the expense of > adding yet another command to remember. Another point here is that we are running low on single-letter backslash command names in psql. I'm not sure that "SET SEARCH_PATH" is so useful as to justify using up one of the ones that are left. ISTM there was some discussion awhile back about user-definable typing shortcuts in psql. I don't recall any details, but being able to set up "SET SEARCH_PATH" as a user-definable shortcut if it's useful to you would eliminate the question about whether it's useful to everyone. regards, tom lane
On Tue, Jul 10, 2012 at 12:00:06PM -0400, Tom Lane wrote: > Josh Kupershmidt <schmiddy@gmail.com> writes: > > On Tue, Jul 10, 2012 at 2:09 AM, Colin 't Hart <colin@sharpheart.org> wrote: > >> Attached please find a trivial patch for psql which adds a \n > >> meta command as a shortcut for typing set search_path =. > > > I think the use-case is a bit narrow: saving a few characters > > typing on a command not everyone uses very often (I don't), at the > > expense of adding yet another command to remember. > > Another point here is that we are running low on single-letter > backslash command names in psql. I'm not sure that "SET > SEARCH_PATH" is so useful as to justify using up one of the ones > that are left. > > ISTM there was some discussion awhile back about user-definable > typing shortcuts in psql. In some sense, we already have them: \set FOO 'SELECT * FROM pg_stat_activity;' ... :FOO Was there more to it? Cheers, David. -- David Fetter <david@fetter.org> http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fetter@gmail.com iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate
On Tue, Jul 10, 2012 at 06:26:22PM +0200, Colin 't Hart wrote: > On 10 July 2012 18:24, David Fetter <david@fetter.org> wrote: > > > On Tue, Jul 10, 2012 at 12:00:06PM -0400, Tom Lane wrote: > > > Josh Kupershmidt <schmiddy@gmail.com> writes: > > > > On Tue, Jul 10, 2012 at 2:09 AM, Colin 't Hart <colin@sharpheart.org> > > wrote: > > > >> Attached please find a trivial patch for psql which adds a \n > > > >> meta command as a shortcut for typing set search_path =. > > > > > > > I think the use-case is a bit narrow: saving a few characters > > > > typing on a command not everyone uses very often (I don't), at the > > > > expense of adding yet another command to remember. > > > > > > Another point here is that we are running low on single-letter > > > backslash command names in psql. I'm not sure that "SET > > > SEARCH_PATH" is so useful as to justify using up one of the ones > > > that are left. > > > > > > ISTM there was some discussion awhile back about user-definable > > > typing shortcuts in psql. > > > > In some sense, we already have them: > > > > \set FOO 'SELECT * FROM pg_stat_activity;' > > ... > > :FOO > > > > Was there more to it? > > Can I pass a parameter to ":FOO" ? That'd be the "more," I suppose. Cheers, David. -- David Fetter <david@fetter.org> http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fetter@gmail.com iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate
David Fetter <david@fetter.org> writes: > On Tue, Jul 10, 2012 at 12:00:06PM -0400, Tom Lane wrote: >> ISTM there was some discussion awhile back about user-definable >> typing shortcuts in psql. > In some sense, we already have them: Good point: regression=# show search_path ; search_path ----------------"$user",public (1 row) regression=# \set n 'set search_path =' regression=# :n foo; SET regression=# show search_path ;search_path -------------foo (1 row) So maybe what's needed here is a documentation example showing how you can use a \set in ~/.psqlrc to provide this sort of functionality. regards, tom lane
Am 10.07.2012 18:44, schrieb Tom Lane: > David Fetter <david@fetter.org> writes: >> On Tue, Jul 10, 2012 at 12:00:06PM -0400, Tom Lane wrote: >>> ISTM there was some discussion awhile back about user-definable >>> typing shortcuts in psql. > >> In some sense, we already have them: > > Good point: > > regression=# show search_path ; > search_path > ---------------- > "$user",public > (1 row) > > regression=# \set n 'set search_path =' > regression=# :n foo; > SET > regression=# show search_path ; > search_path > ------------- > foo > (1 row) Well, a separate command would be mandatory to have tab-completion? Maybe not a single-letter one, but I really would appreciate such an command. Setting the search_path is a thing I do several times a day. Björn > > So maybe what's needed here is a documentation example showing how you > can use a \set in ~/.psqlrc to provide this sort of functionality. > > regards, tom lane >
On 10 July 2012 18:00, Tom Lane <tgl@sss.pgh.pa.us> wrote:
And these could be setup to be available on psql startup by adding them to .psqlrc
While I like my \n idea (heck, I thought of it :-) ), this would be a very good generic solution.
I did a quick search but couldn't find the relevant discussion: do you remember roughly when it was?
If I find it I could have a go at trying to implement it, but it might exceed my ability in C...
Cheers,
Colin
Josh Kupershmidt <schmiddy@gmail.com> writes:Another point here is that we are running low on single-letter backslash
> On Tue, Jul 10, 2012 at 2:09 AM, Colin 't Hart <colin@sharpheart.org> wrote:
>> Attached please find a trivial patch for psql which adds a \n meta command
>> as a shortcut for typing set search_path =.
> I think the use-case is a bit narrow: saving a few characters typing
> on a command not everyone uses very often (I don't), at the expense of
> adding yet another command to remember.
command names in psql. I'm not sure that "SET SEARCH_PATH" is so useful
as to justify using up one of the ones that are left.
ISTM there was some discussion awhile back about user-definable typing
shortcuts in psql. I don't recall any details, but being able to set
up "SET SEARCH_PATH" as a user-definable shortcut if it's useful to you
would eliminate the question about whether it's useful to everyone.
And these could be setup to be available on psql startup by adding them to .psqlrc
While I like my \n idea (heck, I thought of it :-) ), this would be a very good generic solution.
I did a quick search but couldn't find the relevant discussion: do you remember roughly when it was?
If I find it I could have a go at trying to implement it, but it might exceed my ability in C...
Cheers,
Colin
On 10 July 2012 18:24, David Fetter <david@fetter.org> wrote:
Can I pass a parameter to ":FOO" ?
Cheers,
Colin
On Tue, Jul 10, 2012 at 12:00:06PM -0400, Tom Lane wrote:In some sense, we already have them:
> Josh Kupershmidt <schmiddy@gmail.com> writes:
> > On Tue, Jul 10, 2012 at 2:09 AM, Colin 't Hart <colin@sharpheart.org> wrote:
> >> Attached please find a trivial patch for psql which adds a \n
> >> meta command as a shortcut for typing set search_path =.
>
> > I think the use-case is a bit narrow: saving a few characters
> > typing on a command not everyone uses very often (I don't), at the
> > expense of adding yet another command to remember.
>
> Another point here is that we are running low on single-letter
> backslash command names in psql. I'm not sure that "SET
> SEARCH_PATH" is so useful as to justify using up one of the ones
> that are left.
>
> ISTM there was some discussion awhile back about user-definable
> typing shortcuts in psql.
\set FOO 'SELECT * FROM pg_stat_activity;'
...
:FOO
Was there more to it?
Can I pass a parameter to ":FOO" ?
Cheers,
Colin