From 87647fab7f8ce607de4cfc098cd9a8519149bc31 Mon Sep 17 00:00:00 2001
From: Craig Ringer <craig@2ndquadrant.com>
Date: Wed, 31 May 2017 09:10:33 +0800
Subject: [PATCH v1] Provide numeric version from pg_config

Add pg_config --version-num to print integer version, for scripts/tools
---
 src/bin/pg_config/pg_config.c | 2 ++
 src/common/config_info.c      | 6 +++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/bin/pg_config/pg_config.c b/src/bin/pg_config/pg_config.c
index fa2a5a9..3e576fa 100644
--- a/src/bin/pg_config/pg_config.c
+++ b/src/bin/pg_config/pg_config.c
@@ -64,6 +64,7 @@ static const InfoItem info_items[] = {
 	{"--ldflags_sl", "LDFLAGS_SL"},
 	{"--libs", "LIBS"},
 	{"--version", "VERSION"},
+	{"--version-num", "VERSION_NUM"},
 	{NULL, NULL}
 };
 
@@ -100,6 +101,7 @@ help(void)
 	printf(_("  --ldflags_sl          show LDFLAGS_SL value used when PostgreSQL was built\n"));
 	printf(_("  --libs                show LIBS value used when PostgreSQL was built\n"));
 	printf(_("  --version             show the PostgreSQL version\n"));
+	printf(_("  --version-num         show the PostgreSQL version in integer form\n"));
 	printf(_("  -?, --help            show this help, then exit\n"));
 	printf(_("\nWith no arguments, all known items are shown.\n\n"));
 	printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
diff --git a/src/common/config_info.c b/src/common/config_info.c
index ad506be..e056f91 100644
--- a/src/common/config_info.c
+++ b/src/common/config_info.c
@@ -39,7 +39,7 @@ get_configdata(const char *my_exec_path, size_t *configdata_len)
 	int			i = 0;
 
 	/* Adjust this to match the number of items filled below */
-	*configdata_len = 23;
+	*configdata_len = 24;
 	configdata = (ConfigData *) palloc(*configdata_len * sizeof(ConfigData));
 
 	configdata[i].name = pstrdup("BINDIR");
@@ -200,6 +200,10 @@ get_configdata(const char *my_exec_path, size_t *configdata_len)
 	configdata[i].setting = pstrdup("PostgreSQL " PG_VERSION);
 	i++;
 
+	configdata[i].name = pstrdup("VERSION_NUM");
+	configdata[i].setting = pstrdup(CppAsString2(PG_VERSION_NUM));
+	i++;
+
 	Assert(i == *configdata_len);
 
 	return configdata;
-- 
2.9.4

