Hi all Attached is a small patch to teach pg_config how to output a --version-num
With Pg 10, parsing versions got more annoying. Especially with "10beta1", "9.6beta2" etc into the mix. It makes no sense to force tools and scripts to do this when we can just expose a sensible pre-formatted one at no cost to us. Personally I'd like to backpatch this into supported back branches, but just having it in pg 10 would be a help. -- Craig Ringer http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services
From 87647fab7f8ce607de4cfc098cd9a8519149bc31 Mon Sep 17 00:00:00 2001 From: Craig Ringer <cr...@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-b...@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
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers