select version() with internal number version?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

select version() with internal number version?

Luca Ferrari-2
HI all,
I see a lot of external tools that do a 'SELECT version()' and then
parse the output to get the version number (e.g., 10.4).
My opinion is that this is not a good approach, since the output of
version includes a lot of information and can mismatch a poorly
written regular expression. It would be better to use pg_config
--version, byt again there is the needing for mangling the data.
Is there any way to get directly the PostgreSQL version number?

Thanks,
Luca

Reply | Threaded
Open this post in threaded view
|

Re: select version() with internal number version?

Wèi Cōngruì
SHOW server_version;
SHOW server_version_num;

I can fetch the version by these two statement.

On Thu, Aug 9, 2018 at 3:01 PM Luca Ferrari <[hidden email]> wrote:
HI all,
I see a lot of external tools that do a 'SELECT version()' and then
parse the output to get the version number (e.g., 10.4).
My opinion is that this is not a good approach, since the output of
version includes a lot of information and can mismatch a poorly
written regular expression. It would be better to use pg_config
--version, byt again there is the needing for mangling the data.
Is there any way to get directly the PostgreSQL version number?

Thanks,
Luca

Reply | Threaded
Open this post in threaded view
|

Re: select version() with internal number version?

Tom Lane-2
=?UTF-8?B?V8OoaSBDxY1uZ3J1w6w=?= <[hidden email]> writes:
> On Thu, Aug 9, 2018 at 3:01 PM Luca Ferrari <[hidden email]> wrote:
>> Is there any way to get directly the PostgreSQL version number?

> SHOW server_version;
> SHOW server_version_num;

Also, if you're using libpq, see PQserverVersion() which
(a) avoids a round trip to the server, and (b) works further back
than server_version_num, though that issue is probably academic
to most folk at this point (server_version_num appeared in 8.2).

                        regards, tom lane

Reply | Threaded
Open this post in threaded view
|

Re: select version() with internal number version?

Luca Ferrari-2
On Thu, Aug 9, 2018 at 3:51 PM Tom Lane <[hidden email]> wrote:
> Also, if you're using libpq, see PQserverVersion() which
> (a) avoids a round trip to the server, and (b) works further back
> than server_version_num, though that issue is probably academic
> to most folk at this point (server_version_num appeared in 8.2).

Thanks but server_version_num is what I was looking for, since I need
to get the version number from outside PostgreSQL in foreign languages
(python, perl, etc).
I don't believe going back than 8.2 is a metter in this case, since
this is for supporting tools that should not...ehm...support any more
EOL versions.

Luca

Previous Thread Next Thread