How to show the current schema or search path in the psql PROMP

Started by Schwaighofer Clemensalmost 16 years ago12 messagesgeneral
Jump to latest
#1Schwaighofer Clemens
clemens.schwaighofer@tequila.jp

Hi,

I am trying to figure out how I can show the current search_path, or
better the first search_path entry (the active schema) in the PROMPT
variable for psql.

Is there any way to do that? I couldn't find anything useful ...

--
★ Clemens 呉 Schwaighofer
★ IT Engineer/Web Producer/Planning
★ E-Graphics Communications SP Digital
★ 6-17-2 Ginza Chuo-ku, Tokyo 104-8167, JAPAN
★ Tel: +81-(0)3-3545-7706
★ Fax: +81-(0)3-3545-7343
http://www.e-gra.co.jp

This e-mail is intended only for the named person or entity to which
it is addressed and contains valuable business information that is
privileged, confidential and/or otherwise protected from disclosure.
If you received this e-mail in error, any review, use, dissemination,
distribution or copying of this e-mail is strictly prohibited.
Please notify us immediately of the error via e-mail to
disclaimer@tbwaworld.com and please delete the e-mail from your system, retaining no copies in any media.
We appreciate your cooperation.

#2Joshua Tolley
eggyknap@gmail.com
In reply to: Schwaighofer Clemens (#1)
Re: How to show the current schema or search path in the psql PROMP

On Wed, Jun 09, 2010 at 05:52:49PM +0900, Schwaighofer Clemens wrote:

Hi,

I am trying to figure out how I can show the current search_path, or
better the first search_path entry (the active schema) in the PROMPT
variable for psql.

Is there any way to do that? I couldn't find anything useful ...

5432 josh@josh# SHOW search_path;
search_path
----------------
"$user",public
(1 row)

--
Joshua Tolley / eggyknap
End Point Corporation
http://www.endpoint.com

#3Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Joshua Tolley (#2)
Re: How to show the current schema or search path in the psql PROMP

On 06/11/2010 10:23 AM, Joshua Tolley wrote:

On Wed, Jun 09, 2010 at 05:52:49PM +0900, Schwaighofer Clemens wrote:

Hi,

I am trying to figure out how I can show the current search_path, or
better the first search_path entry (the active schema) in the PROMPT
variable for psql.

Is there any way to do that? I couldn't find anything useful ...

5432 josh@josh# SHOW search_path;
search_path
----------------
"$user",public
(1 row)

--
Joshua Tolley / eggyknap
End Point Corporation
http://www.endpoint.com

From here:
http://www.postgresql.org/docs/8.4/interactive/functions-info.html
current_schema[()]

Maybe combined with
%`command`

The output of command, similar to ordinary "back-tick" substitution.

http://www.postgresql.org/docs/8.4/interactive/app-psql.html

--
Adrian Klaver
adrian.klaver@gmail.com

#4Scott Marlowe
scott.marlowe@gmail.com
In reply to: Schwaighofer Clemens (#1)
Re: How to show the current schema or search path in the psql PROMP

On Wed, Jun 9, 2010 at 2:52 AM, Schwaighofer Clemens
<clemens.schwaighofer@tequila.jp> wrote:

Hi,

I am trying to figure out how I can show the current search_path, or
better the first search_path entry (the active schema) in the PROMPT
variable for psql.

Is there any way to do that? I couldn't find anything useful ...

http://www.postgresql.org/docs/8.3/static/app-psql.html#APP-PSQL-PROMPTING

There are lots of things you can put into a prompt, but that doesn't
appear to be one of them. Seems like a reasonable feature request.

#5Scott Marlowe
scott.marlowe@gmail.com
In reply to: Adrian Klaver (#3)
Re: How to show the current schema or search path in the psql PROMP

On Fri, Jun 11, 2010 at 11:29 AM, Adrian Klaver <adrian.klaver@gmail.com> wrote:

On 06/11/2010 10:23 AM, Joshua Tolley wrote:

On Wed, Jun 09, 2010 at 05:52:49PM +0900, Schwaighofer Clemens wrote:

Hi,

I am trying to figure out how I can show the current search_path, or
better the first search_path entry (the active schema) in the PROMPT
variable for psql.

Is there any way to do that? I couldn't find anything useful ...

5432 josh@josh# SHOW search_path;
  search_path
----------------
 "$user",public
(1 row)

--
Joshua Tolley / eggyknap
End Point Corporation
http://www.endpoint.com

From here:
http://www.postgresql.org/docs/8.4/interactive/functions-info.html
current_schema[()]

Maybe combined with
%`command`

   The output of command, similar to ordinary "back-tick" substitution.

http://www.postgresql.org/docs/8.4/interactive/app-psql.html

But that runs a shell command, how's that supposed to get the
search_path? I've been trying to think up a solution to that and
can't come up with one.

#6Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Scott Marlowe (#5)
Re: How to show the current schema or search path in the psql PROMP

On 06/11/2010 11:10 AM, Scott Marlowe wrote:

On Fri, Jun 11, 2010 at 11:29 AM, Adrian Klaver<adrian.klaver@gmail.com> wrote:

On 06/11/2010 10:23 AM, Joshua Tolley wrote:

On Wed, Jun 09, 2010 at 05:52:49PM +0900, Schwaighofer Clemens wrote:

Hi,

I am trying to figure out how I can show the current search_path, or
better the first search_path entry (the active schema) in the PROMPT
variable for psql.

Is there any way to do that? I couldn't find anything useful ...

5432 josh@josh# SHOW search_path;
search_path
----------------
"$user",public
(1 row)

--
Joshua Tolley / eggyknap
End Point Corporation
http://www.endpoint.com

From here:
http://www.postgresql.org/docs/8.4/interactive/functions-info.html
current_schema[()]

Maybe combined with
%`command`

The output of command, similar to ordinary "back-tick" substitution.

http://www.postgresql.org/docs/8.4/interactive/app-psql.html

But that runs a shell command, how's that supposed to get the
search_path? I've been trying to think up a solution to that and
can't come up with one.

I tried running a psql command using current_schema. It got the schema,
unfortunately on a different session than the one I was in. So no it
will not work.

--
Adrian Klaver
adrian.klaver@gmail.com

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Scott Marlowe (#5)
Re: How to show the current schema or search path in the psql PROMP

Scott Marlowe <scott.marlowe@gmail.com> writes:

But that runs a shell command, how's that supposed to get the
search_path? I've been trying to think up a solution to that and
can't come up with one.

Yeah, and you do *not* want the prompt mechanism trying to send SQL
commands...

regards, tom lane

#8Scott Marlowe
scott.marlowe@gmail.com
In reply to: Tom Lane (#7)
Re: How to show the current schema or search path in the psql PROMP

On Fri, Jun 11, 2010 at 2:18 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Scott Marlowe <scott.marlowe@gmail.com> writes:

But that runs a shell command, how's that supposed to get the
search_path?  I've been trying to think up a solution to that and
can't come up with one.

Yeah, and you do *not* want the prompt mechanism trying to send SQL
commands...

Would a more generic way to access pgsql settings in a \set prompt be useful?

#9Clemens Schwaighofer
clemens_schwaighofer@e-gra.co.jp
In reply to: Scott Marlowe (#8)
Re: How to show the current schema or search path in the psql PROMP

Right now I added two simple wrappers in my .psqlrc

\set shsh 'SHOW search_path;'
\set setsh 'SET search_path TO'

So I can at least set and check the schema more quickly.

But seeing it in the PROMPT would be th best.

On Sat, Jun 12, 2010 at 05:26, Scott Marlowe <scott.marlowe@gmail.com> wrote:

On Fri, Jun 11, 2010 at 2:18 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Scott Marlowe <scott.marlowe@gmail.com> writes:

But that runs a shell command, how's that supposed to get the
search_path?  I've been trying to think up a solution to that and
can't come up with one.

Yeah, and you do *not* want the prompt mechanism trying to send SQL
commands...

Would a more generic way to access pgsql settings in a \set prompt be useful?

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

--
★ Clemens 呉 Schwaighofer
★ IT Engineer/Web Producer/Planning
★ E-Graphics Communications SP Digital
★ 6-17-2 Ginza Chuo-ku, Tokyo 104-8167, JAPAN
★ Tel: +81-(0)3-3545-7706
★ Fax: +81-(0)3-3545-7343
http://www.e-gra.co.jp

This e-mail is intended only for the named person or entity to which
it is addressed and contains valuable business information that is
privileged, confidential and/or otherwise protected from disclosure.
If you received this e-mail in error, any review, use, dissemination,
distribution or copying of this e-mail is strictly prohibited.
Please notify us immediately of the error via e-mail to
disclaimer@tbwaworld.com and please delete the e-mail from your system, retaining no copies in any media.
We appreciate your cooperation.

#10Alban Hertroys
dalroi@solfertje.student.utwente.nl
In reply to: Clemens Schwaighofer (#9)
Re: How to show the current schema or search path in the psql PROMP

On 14 Jun 2010, at 2:02, Clemens Schwaighofer wrote:

Right now I added two simple wrappers in my .psqlrc

\set shsh 'SHOW search_path;'
\set setsh 'SET search_path TO'

So I can at least set and check the schema more quickly.

That only saves you a few key-presses though. Is your psql built with libreadline? Without it you don't get TAB-completion, that would be a nuisance!

Alban Hertroys

--
Screwing up is an excellent way to attach something to the ceiling.

!DSPAM:737,4c160039286219954085656!

#11Schwaighofer Clemens
clemens.schwaighofer@tequila.jp
In reply to: Alban Hertroys (#10)
Re: How to show the current schema or search path in the psql PROMP

On Mon, Jun 14, 2010 at 19:10, Alban Hertroys
<dalroi@solfertje.student.utwente.nl> wrote:

On 14 Jun 2010, at 2:02, Clemens Schwaighofer wrote:

Right now I added two simple wrappers in my .psqlrc

\set shsh 'SHOW search_path;'
\set setsh 'SET search_path TO'

So I can at least set and check the schema more quickly.

That only saves you a few key-presses though. Is your psql built with libreadline? Without it you don't get TAB-completion, that would be a nuisance!

even with readline it is quicker to type :shsh to see the current
schema thant to type full thing.

--
★ Clemens 呉 Schwaighofer
★ IT Engineer/Web Producer/Planning
★ E-Graphics Communications SP Digital
★ 6-17-2 Ginza Chuo-ku, Tokyo 104-8167, JAPAN
★ Tel: +81-(0)3-3545-7706
★ Fax: +81-(0)3-3545-7343
http://www.e-gra.co.jp

This e-mail is intended only for the named person or entity to which
it is addressed and contains valuable business information that is
privileged, confidential and/or otherwise protected from disclosure.
If you received this e-mail in error, any review, use, dissemination,
distribution or copying of this e-mail is strictly prohibited.
Please notify us immediately of the error via e-mail to
disclaimer@tbwaworld.com and please delete the e-mail from your system, retaining no copies in any media.
We appreciate your cooperation.

#12Alban Hertroys
dalroi@solfertje.student.utwente.nl
In reply to: Schwaighofer Clemens (#11)
Re: How to show the current schema or search path in the psql PROMP

On 14 Jun 2010, at 12:14, Schwaighofer Clemens wrote:

On Mon, Jun 14, 2010 at 19:10, Alban Hertroys
<dalroi@solfertje.student.utwente.nl> wrote:

On 14 Jun 2010, at 2:02, Clemens Schwaighofer wrote:

Right now I added two simple wrappers in my .psqlrc

\set shsh 'SHOW search_path;'
\set setsh 'SET search_path TO'

So I can at least set and check the schema more quickly.

That only saves you a few key-presses though. Is your psql built with libreadline? Without it you don't get TAB-completion, that would be a nuisance!

even with readline it is quicker to type :shsh to see the current
schema thant to type full thing.

Do you realise you only save 3 key-presses there, compared to "sh[TAB]sea[TAB];"? That's a rhetorical question btw, it's entirely up to you to define any short-cuts you want.

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.

!DSPAM:737,4c160855286213993713473!