Re: How to get shorter SERVER_VERSION in psql-prompt? - Mailing list pgsql-general

From Christoph Moench-Tegeder
Subject Re: How to get shorter SERVER_VERSION in psql-prompt?
Date
Msg-id 20180903213447.yruv2ua2qlik5r7h@squirrel.exwg.net
Whole thread Raw
In response to How to get shorter SERVER_VERSION in psql-prompt?  (Andreas Joseph Krogh <andreas@visena.com>)
Responses Sv: Re: How to get shorter SERVER_VERSION in psql-prompt?  (Andreas Joseph Krogh <andreas@visena.com>)
List pgsql-general
## 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.


pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: How to get shorter SERVER_VERSION in psql-prompt?
Next
From: Andreas Joseph Krogh
Date:
Subject: Sv: Re: How to get shorter SERVER_VERSION in psql-prompt?