Skip to content

Instantly share code, notes, and snippets.

@sandcastle
Created September 16, 2019 06:40
Show Gist options
  • Save sandcastle/8640f92c9c6367135a4d9c71e19ae460 to your computer and use it in GitHub Desktop.
Save sandcastle/8640f92c9c6367135a4d9c71e19ae460 to your computer and use it in GitHub Desktop.
Determine the version of postgres a statement is run on.
select version();
-- PostgreSQL 9.6.12 on x86_64-pc-linux-musl, compiled by gcc (Alpine 8.2.0) 8.2.0, 64-bit
SHOW server_version;
-- 9.6.12
SELECT current_setting('server_version_num');
-- 90612
select current_setting('server_version');
-- 9.6.12
-- major version
select (regexp_matches(current_setting('server_version'), '(\d+)\.(\d+)\.(\d+)'))[1];
-- 9
-- minor version
select (regexp_matches(current_setting('server_version'), '(\d+)\.(\d+)\.(\d+)'))[2];
-- 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment