Обсуждение: How to get shorter SERVER_VERSION in psql-prompt?

Поиск
Список
Период
Сортировка

How to get shorter SERVER_VERSION in psql-prompt?

От
Andreas Joseph Krogh
Дата:
Hi all, I'm using the Ubuntu-packages and have this in my .psqlrc:
 
\set PROMPT1 '%[%033[35m%]%n@%m:%>%[%033[0m%] %:server_version: %[%033[32m%]%/%[%033[0m%]%R%# '
 
This results in this verver_version:
10.5 (Ubuntu 10.5-1.pgdg18.04+1)
 
Is it possible to adjust this somehow so it outputs only "10.5"?
 
Thanks in advance.
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
Вложения

Re: How to get shorter SERVER_VERSION in psql-prompt?

От
Alvaro Herrera
Дата:
On 2018-Sep-03, Andreas Joseph Krogh wrote:

> Hi all, I'm using the Ubuntu-packages and have this in my .psqlrc:
>  
> \set PROMPT1 '%[%033[35m%]%n@%m:%>%[%033[0m%] %:server_version: 
> %[%033[32m%]%/%[%033[0m%]%R%# '
>   
> This results in this verver_version:
> 10.5 (Ubuntu 10.5-1.pgdg18.04+1)
>   
> Is it possible to adjust this somehow so it outputs only "10.5"?

Well, where does that server_version come from?  Try adding this
somewhere to .psqlrc:

select setting as server_version from pg_settings where name = 'server_version' \gset

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


Re: How to get shorter SERVER_VERSION in psql-prompt?

От
Christoph Moench-Tegeder
Дата:
## Andreas Joseph Krogh (andreas@visena.com):

> This results in this verver_version:
> 10.5 (Ubuntu 10.5-1.pgdg18.04+1)
>   
> Is it possible to adjust this somehow so it outputs only "10.5"?

On Debian/Ubuntu, all version strings are somewhat extended.
Luckily, with the power of SQL we're not completely helpless, so try
this in your .psqlrc (somewhat simpler than your prompt, but you
get the idea):

select substring(current_setting('server_version') from '#"[^ ]+#"( +%)?' for '#') as short_server_ver\gset
\set PROMPT1 '%/ %:short_server_ver: %R%# '

Yes, that works across \c.

Happy prompting,
Christoph

-- 
Spare Space.


Sv: Re: How to get shorter SERVER_VERSION in psql-prompt?

От
Andreas Joseph Krogh
Дата:
På mandag 03. september 2018 kl. 23:03:10, skrev Alvaro Herrera <alvherre@2ndquadrant.com>:
On 2018-Sep-03, Andreas Joseph Krogh wrote:

> Hi all, I'm using the Ubuntu-packages and have this in my .psqlrc:
>  
> \set PROMPT1 '%[%033[35m%]%n@%m:%>%[%033[0m%] %:server_version:
> %[%033[32m%]%/%[%033[0m%]%R%# '
>   
> This results in this verver_version:
> 10.5 (Ubuntu 10.5-1.pgdg18.04+1)
>   
> Is it possible to adjust this somehow so it outputs only "10.5"?

Well, where does that server_version come from?  Try adding this
somewhere to .psqlrc:

select setting as server_version from pg_settings where name = 'server_version' \gset
 
select setting as server_version from pg_settings where name = 'server_version';
┌──────────────────────────────────┐
│          server_version          │
├──────────────────────────────────┤
│ 10.5 (Ubuntu 10.5-1.pgdg18.04+1) │
└──────────────────────────────────┘
(1 row)

 
I use packages from http://apt.postgresql.org/pub/repos/apt/
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
 
Вложения

Sv: Re: How to get shorter SERVER_VERSION in psql-prompt?

От
Andreas Joseph Krogh
Дата:
På mandag 03. september 2018 kl. 23:34:48, skrev Christoph Moench-Tegeder <cmt@burggraben.net>:
## Andreas Joseph Krogh (andreas@visena.com):

> This results in this verver_version:
> 10.5 (Ubuntu 10.5-1.pgdg18.04+1)
>   
> Is it possible to adjust this somehow so it outputs only "10.5"?

On Debian/Ubuntu, all version strings are somewhat extended.
Luckily, with the power of SQL we're not completely helpless, so try
this in your .psqlrc (somewhat simpler than your prompt, but you
get the idea):

select substring(current_setting('server_version') from '#"[^ ]+#"( +%)?' for '#') as short_server_ver\gset
\set PROMPT1 '%/ %:short_server_ver: %R%# '

Yes, that works across \c.
 
Nice, thanks!
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
 
Вложения

Re: Sv: Re: How to get shorter SERVER_VERSION in psql-prompt?

От
Alvaro Herrera
Дата:
On 2018-Sep-03, Andreas Joseph Krogh wrote:

> select setting as server_version from pg_settings where name = 
> 'server_version';
>  ┌──────────────────────────────────┐
>  │          server_version          │
>  ├──────────────────────────────────┤
>  │ 10.5 (Ubuntu 10.5-1.pgdg18.04+1) │
>  └──────────────────────────────────┘

Ugh.  (So this is coming from "configure --with-extra-version" stuff)

I guess you could just split it out at the first whitespace ...

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


Re: Sv: Re: How to get shorter SERVER_VERSION in psql-prompt?

От
Rob Sargent
Дата:

On 09/03/2018 03:42 PM, Alvaro Herrera wrote:
> On 2018-Sep-03, Andreas Joseph Krogh wrote:
>
>> select setting as server_version from pg_settings where name =
>> 'server_version';
>>   ┌──────────────────────────────────┐
>>   │          server_version          │
>>   ├──────────────────────────────────┤
>>   │ 10.5 (Ubuntu 10.5-1.pgdg18.04+1) │
>>   └──────────────────────────────────┘
> Ugh.  (So this is coming from "configure --with-extra-version" stuff)
>
> I guess you could just split it out at the first whitespace ...
>
Does that also diddle the value of "server_version_num"?



Re: Sv: Re: How to get shorter SERVER_VERSION in psql-prompt?

От
Christoph Moench-Tegeder
Дата:
## Rob Sargent (robjsargent@gmail.com):

> > Ugh.  (So this is coming from "configure --with-extra-version" stuff)

> Does that also diddle the value of "server_version_num"?

No, that's still integer-format (it's unchanged and you can cast it
straight into INTEGER).

Gruss,
Christoph

-- 
Spare Space.


Sv: Re: Sv: Re: How to get shorter SERVER_VERSION in psql-prompt?

От
Andreas Joseph Krogh
Дата:
På mandag 03. september 2018 kl. 23:43:46, skrev Rob Sargent <robjsargent@gmail.com>:


On 09/03/2018 03:42 PM, Alvaro Herrera wrote:
> On 2018-Sep-03, Andreas Joseph Krogh wrote:
>
>> select setting as server_version from pg_settings where name =
>> 'server_version';
>>   ┌──────────────────────────────────┐
>>   │          server_version          │
>>   ├──────────────────────────────────┤
>>   │ 10.5 (Ubuntu 10.5-1.pgdg18.04+1) │
>>   └──────────────────────────────────┘
> Ugh.  (So this is coming from "configure --with-extra-version" stuff)
>
> I guess you could just split it out at the first whitespace ...
>
Does that also diddle the value of "server_version_num"?
 
No:
show server_version_num;
┌────────────────────┐
│ server_version_num │
├────────────────────┤
│ 100005             │
└────────────────────┘
(1 row)

 
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
 
Вложения