Skip to content

Commit c3107f1

Browse files
committed
Teach libpq to decode server version correctly from future servers.
Beginning with the next development cycle, PG servers will report two-part not three-part version numbers. Fix libpq so that it will compute the correct numeric representation of such server versions for reporting by PQserverVersion(). It's desirable to get this into the field and back-patched ASAP, so that older clients are more likely to understand the new server version numbering by the time any such servers are in the wild. (The results with an old client would probably not be catastrophic anyway for a released server; for example "10.1" would be interpreted as 100100 which would be wrong in detail but would not likely cause an old client to misbehave badly. But "10devel" or "10beta1" would result in sversion==0 which at best would result in disabling all use of modern features.) Extracted from a patch by Peter Eisentraut; comments added by me Patch: <802ec140-635d-ad86-5fdf-d3af0e260c22@2ndquadrant.com>
1 parent 5630bd2 commit c3107f1

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/interfaces/libpq/fe-exec.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -981,14 +981,31 @@ pqSaveParameterStatus(PGconn *conn, const char *name, const char *value)
981981

982982
cnt = sscanf(value, "%d.%d.%d", &vmaj, &vmin, &vrev);
983983

984-
if (cnt < 2)
985-
conn->sversion = 0; /* unknown */
986-
else
984+
if (cnt == 3)
987985
{
988-
if (cnt == 2)
989-
vrev = 0;
986+
/* old style, e.g. 9.6.1 */
990987
conn->sversion = (100 * vmaj + vmin) * 100 + vrev;
991988
}
989+
else if (cnt == 2)
990+
{
991+
if (vmaj >= 10)
992+
{
993+
/* new style, e.g. 10.1 */
994+
conn->sversion = 100 * 100 * vmaj + vmin;
995+
}
996+
else
997+
{
998+
/* old style without minor version, e.g. 9.6devel */
999+
conn->sversion = (100 * vmaj + vmin) * 100;
1000+
}
1001+
}
1002+
else if (cnt == 1)
1003+
{
1004+
/* new style without minor version, e.g. 10devel */
1005+
conn->sversion = 100 * 100 * vmaj;
1006+
}
1007+
else
1008+
conn->sversion = 0; /* unknown */
9921009
}
9931010
}
9941011

0 commit comments

Comments
 (0)