Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get comparable PostgreSQL version number

I need to make sure that an available PostgreSQL version is not lower than required one. The version string could be requested as follows:

SELECT VERSION();

It returns me something like:

PostgreSQL 9.5.4, compiled by Visual C++ build 1800, 64-bit

Theoretically I could parse this string, but I am not sure that future versions of PostgreSQL server will keep this word order.

Does PostgreSQL have some predictable version report possibly split in major and minor version number?

like image 642
Paul Avatar asked Oct 17 '25 22:10

Paul


2 Answers

show server_version_num; --returns 90602::text
show server_version; --returns 9.6.2::text
like image 143
Łukasz Kamiński Avatar answered Oct 21 '25 08:10

Łukasz Kamiński


https://blog.2ndquadrant.com/finding-postgresql-version/ says:

You can use that more easily within an SQL query like this

SELECT current_setting('server_version_num');
like image 27
Paul Avatar answered Oct 21 '25 08:10

Paul