Thread

  1. [PATCH] psql \n shortcut for set search_path =

    Colin 't Hart <colin@sharpheart.org> — 2012-07-10T09:09:34Z

    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
    
  2. Re: [PATCH] psql \n shortcut for set search_path =

    Josh Kupershmidt <schmiddy@gmail.com> — 2012-07-10T14:59:57Z

    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
    
    
  3. Re: [PATCH] psql \n shortcut for set search_path =

    Tom Lane <tgl@sss.pgh.pa.us> — 2012-07-10T16:00:06Z

    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
    
    
  4. Re: [PATCH] psql \n shortcut for set search_path =

    David Fetter <david@fetter.org> — 2012-07-10T16:24:08Z

    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
    
    
  5. Re: [PATCH] psql \n shortcut for set search_path =

    Colin 't Hart <colin@sharpheart.org> — 2012-07-10T16:24:54Z

    On 10 July 2012 18:00, Tom Lane <tgl@sss.pgh.pa.us> 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.  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
    
  6. Re: [PATCH] psql \n shortcut for set search_path =

    Colin 't Hart <colin@sharpheart.org> — 2012-07-10T16:26:22Z

    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" ?
    
    Cheers,
    
    Colin
    
  7. Re: [PATCH] psql \n shortcut for set search_path =

    David Fetter <david@fetter.org> — 2012-07-10T16:29:33Z

    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
    
    
  8. Re: [PATCH] psql \n shortcut for set search_path =

    Tom Lane <tgl@sss.pgh.pa.us> — 2012-07-10T16:44:22Z

    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
    
    
  9. Re: [PATCH] psql \n shortcut for set search_path =

    Björn Häuser <bjoernhaeuser@gmail.com> — 2012-07-10T18:10:06Z

    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
    >