Re: [PATCH] psql \n shortcut for set search_path =

Lists: pgsql-hackers
From: "Colin 't Hart" <colin(at)sharpheart(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: [PATCH] psql \n shortcut for set search_path =
Date: 2012-07-10 09:09:34
Message-ID: CAMon-aT6b3s9mx6BuokBGy0rh5_dPawuV9-8rBW2oLO=k-rPSg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

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

Attachment Content-Type Size
psql_slash_n.patch application/octet-stream 1.1 KB

From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: "Colin 't Hart" <colin(at)sharpheart(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] psql \n shortcut for set search_path =
Date: 2012-07-10 14:59:57
Message-ID: CAK3UJRFE5FyrjAREOFVD=R6Dx6Dfm8N-w=dNJJiUyhyUxHAX8g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jul 10, 2012 at 2:09 AM, Colin 't Hart <colin(at)sharpheart(dot)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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
Cc: "Colin 't Hart" <colin(at)sharpheart(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] psql \n shortcut for set search_path =
Date: 2012-07-10 16:00:06
Message-ID: 22660.1341936006@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Josh Kupershmidt <schmiddy(at)gmail(dot)com> writes:
> On Tue, Jul 10, 2012 at 2:09 AM, Colin 't Hart <colin(at)sharpheart(dot)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


From: David Fetter <david(at)fetter(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Josh Kupershmidt <schmiddy(at)gmail(dot)com>, "Colin 't Hart" <colin(at)sharpheart(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] psql \n shortcut for set search_path =
Date: 2012-07-10 16:24:08
Message-ID: 20120710162408.GB13758@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jul 10, 2012 at 12:00:06PM -0400, Tom Lane wrote:
> Josh Kupershmidt <schmiddy(at)gmail(dot)com> writes:
> > On Tue, Jul 10, 2012 at 2:09 AM, Colin 't Hart <colin(at)sharpheart(dot)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(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)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


From: "Colin 't Hart" <colin(at)sharpheart(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Josh Kupershmidt <schmiddy(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] psql \n shortcut for set search_path =
Date: 2012-07-10 16:24:54
Message-ID: CAMon-aQ8XypcX984VfWyu22vkztn6HYjgb3vrt8fbt42gNx3UA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 10 July 2012 18:00, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Josh Kupershmidt <schmiddy(at)gmail(dot)com> writes:
> > On Tue, Jul 10, 2012 at 2:09 AM, Colin 't Hart <colin(at)sharpheart(dot)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


From: "Colin 't Hart" <colin(at)sharpheart(dot)org>
To: David Fetter <david(at)fetter(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Josh Kupershmidt <schmiddy(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] psql \n shortcut for set search_path =
Date: 2012-07-10 16:26:22
Message-ID: CAMon-aQthOOmOOkURxYY0n5dLQRTQn9kLOZVFQxNi6MZ_Xmv2A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 10 July 2012 18:24, David Fetter <david(at)fetter(dot)org> wrote:

> On Tue, Jul 10, 2012 at 12:00:06PM -0400, Tom Lane wrote:
> > Josh Kupershmidt <schmiddy(at)gmail(dot)com> writes:
> > > On Tue, Jul 10, 2012 at 2:09 AM, Colin 't Hart <colin(at)sharpheart(dot)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


From: David Fetter <david(at)fetter(dot)org>
To: "Colin 't Hart" <colin(at)sharpheart(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Josh Kupershmidt <schmiddy(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] psql \n shortcut for set search_path =
Date: 2012-07-10 16:29:33
Message-ID: 20120710162933.GC13758@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jul 10, 2012 at 06:26:22PM +0200, Colin 't Hart wrote:
> On 10 July 2012 18:24, David Fetter <david(at)fetter(dot)org> wrote:
>
> > On Tue, Jul 10, 2012 at 12:00:06PM -0400, Tom Lane wrote:
> > > Josh Kupershmidt <schmiddy(at)gmail(dot)com> writes:
> > > > On Tue, Jul 10, 2012 at 2:09 AM, Colin 't Hart <colin(at)sharpheart(dot)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(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Fetter <david(at)fetter(dot)org>
Cc: Josh Kupershmidt <schmiddy(at)gmail(dot)com>, "Colin 't Hart" <colin(at)sharpheart(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] psql \n shortcut for set search_path =
Date: 2012-07-10 16:44:22
Message-ID: 23678.1341938662@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

David Fetter <david(at)fetter(dot)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


From: Björn Häuser <bjoernhaeuser(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] psql \n shortcut for set search_path =
Date: 2012-07-10 18:10:06
Message-ID: 4FFC6FFE.5010702@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Am 10.07.2012 18:44, schrieb Tom Lane:
> David Fetter <david(at)fetter(dot)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
>