server_version_num

A read-only server parameter containing the server version number

server_version_num is a read-only configuration parameter reporting the PostgreSQL server version number as an integer.

server_version_num was added in PostgreSQL 8.2.

Usage

server_version_num reports the current server version number as an integer, which represents a canonical version number without needing to parse a textual representation (e.g. 120007 vs 12.7), and can reliably be used to compare versions.

server_version_num reports the value of PG_VERSION_NUM defined when the server was built.

Change history

Examples

Basic usage example for server_version_num:

postgres=# SHOW server_version_num;
 server_version_num 
--------------------
 120007
(1 row)

Comparision of the various forms of server version information which are available:

postgres=# SELECT version(),
                  current_setting('server_version') AS server_version,
                  current_setting('server_version_num') AS server_version_num\gx
-[ RECORD 1 ]------+-------------------------------------------------------------------------------------------------------
version            | PostgreSQL 12.7 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.3.1 20191121 (Red Hat 8.3.1-5), 64-bit
server_version     | 12.7
server_version_num | 120007

Categories

GUC configuration item, PostgreSQL versioning

See also

server_version, version(), Obtain the PostgreSQL version number