pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedqueriing the version of libpq
18+ messages / 11 participants
[nested] [flat]
* queriing the version of libpq
@ 2010-10-05 07:33 Massa, Harald Armin <chef@ghum.de>
0 siblings, 3 replies; 18+ messages in thread
From: Massa, Harald Armin @ 2010-10-05 07:33 UTC (permalink / raw)
To: pgsql-general
With 9.0 there is the new hex encoding for BYTEA, which is activated by
default.
libpq BEFORE 9.0 are not able to decode that encoding.
I am programming with Python, using psycopg2. When psycopg2 is linked with
libpq 9.0, everything works fine with hex-encoding; if psycopg2 is linked
with libpq < 9.0, decoding hex-encoded bytea fails (it stays hexencoded).
This happens because in default configuration psycopg2 calls the
libpq-decode-encoded-bytea function (which is the way it should be done).
Now I would love to have an additional check "is the used psycopg2 linked to
an advanced-enough libpq", to be able to set bytea_output to 'escape' if the
libpq is not worthy.
My question: Which way is available to query the linked libpq version?
My other option is to select 'something_that_gets_casted_to_bytea'::bytea,
and check the return value. BUT that requires a round-trip to the server....
Harald
--
GHUM GmbH
Harald Armin Massa
Spielberger Straße 49
70435 Stuttgart
0173/9409607
Amtsgericht Stuttgart, HRB 734971
-
persuadere.
et programmare
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: queriing the version of libpq
@ 2010-10-05 08:02 Magnus Hagander <magnus@hagander.net>
parent: Massa, Harald Armin <chef@ghum.de>
2 siblings, 1 reply; 18+ messages in thread
From: Magnus Hagander @ 2010-10-05 08:02 UTC (permalink / raw)
To: Massa, Harald Armin <chef@ghum.de>; +Cc: pgsql-general
On Tue, Oct 5, 2010 at 09:33, Massa, Harald Armin <chef@ghum.de> wrote:
> With 9.0 there is the new hex encoding for BYTEA, which is activated by
> default.
> libpq BEFORE 9.0 are not able to decode that encoding.
> I am programming with Python, using psycopg2. When psycopg2 is linked with
> libpq 9.0, everything works fine with hex-encoding; if psycopg2 is linked
> with libpq < 9.0, decoding hex-encoded bytea fails (it stays hexencoded).
> This happens because in default configuration psycopg2 calls the
> libpq-decode-encoded-bytea function (which is the way it should be done).
> Now I would love to have an additional check "is the used psycopg2 linked to
> an advanced-enough libpq", to be able to set bytea_output to 'escape' if the
> libpq is not worthy.
> My question: Which way is available to query the linked libpq version?
> My other option is to select 'something_that_gets_casted_to_bytea'::bytea,
> and check the return value. BUT that requires a round-trip to the server....
You can try calling PQconninfoParse() on a connectino string that has
applicationname= in it. That will fail on anything pre-9.0. Assuming
there's a way to access that function through psycopg2.
But it does outline that fact that it wouldn't suck to have a function
in libpq returning the version so that application can check this at
runtime - clearly it would also be useful when being linked "through"
something like psycopg2.
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: queriing the version of libpq
@ 2010-10-05 14:32 Greg Sabino Mullane <greg@turnstep.com>
parent: Massa, Harald Armin <chef@ghum.de>
2 siblings, 1 reply; 18+ messages in thread
From: Greg Sabino Mullane @ 2010-10-05 14:32 UTC (permalink / raw)
To: pgsql-general
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160
> My question: Which way is available to query the linked libpq version?
That's information your driver should be supplying. For example, in
Perl (DBD::Pg), you would say
if ($dbh->{pg_lib_version} >= 90000) {
I'd raise a bug with psycopg2 if it does not provide that information.
- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 201010051030
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----
iEYEAREDAAYFAkyrNskACgkQvJuQZxSWSsiW7wCfYge62y175Xtsk4drGbnt7UU5
0R4Ani1gxDhNA0xdHoq+xxxROjuC4wh+
=n33y
-----END PGP SIGNATURE-----
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: queriing the version of libpq
@ 2010-10-05 14:38 Magnus Hagander <magnus@hagander.net>
parent: Greg Sabino Mullane <greg@turnstep.com>
0 siblings, 0 replies; 18+ messages in thread
From: Magnus Hagander @ 2010-10-05 14:38 UTC (permalink / raw)
To: Greg Sabino Mullane <greg@turnstep.com>; +Cc: pgsql-general
On Tue, Oct 5, 2010 at 16:32, Greg Sabino Mullane <greg@turnstep.com> wrote:
>> My question: Which way is available to query the linked libpq version?
>
> That's information your driver should be supplying. For example, in
> Perl (DBD::Pg), you would say
>
> if ($dbh->{pg_lib_version} >= 90000) {
>
> I'd raise a bug with psycopg2 if it does not provide that information.
How does the driver figure it out?
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: queriing the version of libpq
@ 2010-10-07 09:23 Peter Eisentraut <peter_e@gmx.net>
parent: Massa, Harald Armin <chef@ghum.de>
2 siblings, 1 reply; 18+ messages in thread
From: Peter Eisentraut @ 2010-10-07 09:23 UTC (permalink / raw)
To: Massa, Harald Armin <chef@ghum.de>; +Cc: pgsql-general
On tis, 2010-10-05 at 09:33 +0200, Massa, Harald Armin wrote:
> Now I would love to have an additional check "is the used psycopg2
> linked to an advanced-enough libpq", to be able to set bytea_output to
> 'escape' if the libpq is not worthy.
This is really something that psycopg2 should work out for you. I
suggest you take up a discussion on this on their mailing list.
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: queriing the version of libpq
@ 2010-10-07 09:34 Devrim GÜNDÜZ <devrim@gunduz.org>
parent: Peter Eisentraut <peter_e@gmx.net>
0 siblings, 1 reply; 18+ messages in thread
From: Devrim GÜNDÜZ @ 2010-10-07 09:34 UTC (permalink / raw)
To: Peter Eisentraut <peter_e@gmx.net>; +Cc: Massa, Harald Armin <chef@ghum.de>; pgsql-general
On Thu, 2010-10-07 at 12:23 +0300, Peter Eisentraut wrote:
> This is really something that psycopg2 should work out for you. I
> suggest you take up a discussion on this on their mailing list.
...which is down over the last 3 weeks or so:
http://www.initd.org/
--
Devrim GÜNDÜZ
PostgreSQL Danışmanı/Consultant, Red Hat Certified Engineer
PostgreSQL RPM Repository: http://yum.pgrpms.org
Community: devrim~PostgreSQL.org, devrim.gunduz~linux.org.tr
http://www.gunduz.org Twitter: http://twitter.com/devrimgunduz
Attachments:
signature.asc (application/pgp-signature, 197B) download
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: queriing the version of libpq
@ 2010-10-07 15:07 A.M. <agentm@themactionfaction.com>
parent: Devrim GÜNDÜZ <devrim@gunduz.org>
0 siblings, 1 reply; 18+ messages in thread
From: A.M. @ 2010-10-07 15:07 UTC (permalink / raw)
To: pgsql-general
On Oct 7, 2010, at 5:34 AM, Devrim GÜNDÜZ wrote:
> On Thu, 2010-10-07 at 12:23 +0300, Peter Eisentraut wrote:
>> This is really something that psycopg2 should work out for you. I
>> suggest you take up a discussion on this on their mailing list.
>
> ...which is down over the last 3 weeks or so:
>
> http://www.initd.org/
In addition, I posted a patch for 9.0 support which was supposed to be rolled in to psycopg2 weeks ago. Now I am stuck pushing my own psycopg2 egg around. The psycopg2 project is too reliant on one person (who has trouble managing his servers)- I wish he would move the project to a public project management service.
I also remember a discussion on the poor state of postgresql drivers for python and which driver the PostgreSQL project should endorse- it looks like the situation has not improved. Here's the thread: http://archives.postgresql.org/pgsql-hackers/2010-02/msg00351.php
Cheers,
M
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: queriing the version of libpq
@ 2010-10-20 23:26 Bruce Momjian <bruce@momjian.us>
parent: A.M. <agentm@themactionfaction.com>
0 siblings, 0 replies; 18+ messages in thread
From: Bruce Momjian @ 2010-10-20 23:26 UTC (permalink / raw)
To: A.M. <agentm@themactionfaction.com>; +Cc: pgsql-general
A.M. wrote:
>
> On Oct 7, 2010, at 5:34 AM, Devrim G?ND?Z wrote:
>
> > On Thu, 2010-10-07 at 12:23 +0300, Peter Eisentraut wrote:
> >> This is really something that psycopg2 should work out for you. I
> >> suggest you take up a discussion on this on their mailing list.
> >
> > ...which is down over the last 3 weeks or so:
> >
> > http://www.initd.org/
>
> In addition, I posted a patch for 9.0 support which was supposed to be
> rolled in to psycopg2 weeks ago. Now I am stuck pushing my own psycopg2
> egg around. The psycopg2 project is too reliant on one person (who has
> trouble managing his servers)- I wish he would move the project to a
> public project management service.
>
> I also remember a discussion on the poor state of postgresql drivers
> for python and which driver the PostgreSQL project should endorse- it
> looks like the situation has not improved. Here's the thread:
> http://archives.postgresql.org/pgsql-hackers/2010-02/msg00351.php
The python driver situation did improve, for a while. :-|
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: queriing the version of libpq
@ 2010-12-14 16:56 Massa, Harald Armin <chef@ghum.de>
parent: Magnus Hagander <magnus@hagander.net>
0 siblings, 2 replies; 18+ messages in thread
From: Massa, Harald Armin @ 2010-12-14 16:56 UTC (permalink / raw)
To: Magnus Hagander <magnus@hagander.net>; +Cc: pgsql-general
>> My question: Which way is available to query the linked libpq version?
> But it does outline that fact that it wouldn't suck to have a >function in libpq returning the version so that application can >check this at runtime - clearly it would also be useful when >being linked "through" something like psycopg2.
did there something happen?
happen as in "an addition of a function to libpq to query its version
without a server roundtrip AFTER libpq has been linked into sth has
been decided for / against"
Harald
--
GHUM GmbH
Harald Armin Massa
Spielberger Straße 49
70435 Stuttgart
0173/9409607
Amtsgericht Stuttgart, HRB 734971
-
persuadere.
et programmare
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: [GENERAL] queriing the version of libpq
@ 2010-12-16 15:56 Magnus Hagander <magnus@hagander.net>
parent: Massa, Harald Armin <chef@ghum.de>
1 sibling, 2 replies; 18+ messages in thread
From: Magnus Hagander @ 2010-12-16 15:56 UTC (permalink / raw)
To: Massa, Harald Armin <chef@ghum.de>; +Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
On Tue, Dec 14, 2010 at 17:56, Massa, Harald Armin <chef@ghum.de> wrote:
>>> My question: Which way is available to query the linked libpq version?
>
>> But it does outline that fact that it wouldn't suck to have a >function in libpq returning the version so that application can >check this at runtime - clearly it would also be useful when >being linked "through" something like psycopg2.
>
> did there something happen?
Stuck in a local git branch. I've rebased on current and added docs,
see attachment.
(moving to hackers as well)
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
Attachments:
pqlibversion.patch (text/x-patch, 3.3K) download
*** a/doc/src/sgml/libpq.sgml
--- b/doc/src/sgml/libpq.sgml
***************
*** 5359,5364 **** void *PQresultAlloc(PGresult *res, size_t nBytes);
--- 5359,5399 ----
</listitem>
</varlistentry>
+ <varlistentry id="libpq-pqlibversion">
+ <term>
+ <function>PQlibVersion</function>
+ <indexterm>
+ <primary>PQlibVersion</primary>
+ <seealso>PQserverVersion</seealso>
+ </indexterm>
+ </term>
+
+ <listitem>
+ <para>
+ Return the version of <productname>libpq</> that is being used.
+ <synopsis>
+ int PQlibVersion(void);
+ </synopsis>
+ </para>
+
+ <para>
+ The result value of this function can be used to determine if
+ a specific function is available in the currently used version
+ of libpq.
+ </para>
+
+ <note>
+ <para>
+ This function appeared in <productname>PostgreSQL</> version 9.1, so
+ it cannot be used to detect required functions in earlier version.
+ Usage of this function will make the application require version
+ 9.1 or newer even if no actual funcionality from this version
+ is required.
+ </para>
+ </note>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</sect1>
*** a/src/interfaces/libpq/exports.txt
--- b/src/interfaces/libpq/exports.txt
***************
*** 159,161 **** PQconnectdbParams 156
--- 159,162 ----
PQconnectStartParams 157
PQping 158
PQpingParams 159
+ PQlibVersion 160
*** a/src/interfaces/libpq/fe-misc.c
--- b/src/interfaces/libpq/fe-misc.c
***************
*** 66,71 **** static int pqSocketCheck(PGconn *conn, int forRead, int forWrite,
--- 66,85 ----
time_t end_time);
static int pqSocketPoll(int sock, int forRead, int forWrite, time_t end_time);
+ /*
+ * PQlibVersion: return the libpq version number
+ */
+ int
+ PQlibVersion(void)
+ {
+ /*
+ * This number is updated by tools/version_stamp.pl, do not
+ * edit manually.
+ */
+ #define LOCAL_PG_VERSION_NUM 90100
+ return LOCAL_PG_VERSION_NUM;
+ #undef LOCAL_PG_VERSION_NUM
+ }
/*
* fputnbytes: print exactly N bytes to a file
*** a/src/interfaces/libpq/libpq-fe.h
--- b/src/interfaces/libpq/libpq-fe.h
***************
*** 547,552 **** extern int lo_export(PGconn *conn, Oid lobjId, const char *filename);
--- 547,555 ----
/* === in fe-misc.c === */
+ /* Get the version of the libpq library in use */
+ extern int PQlibVersion(void);
+
/* Determine length of multibyte encoded char at *s */
extern int PQmblen(const char *s, int encoding);
*** a/src/tools/version_stamp.pl
--- b/src/tools/version_stamp.pl
***************
*** 88,93 **** sed_file("src/include/pg_config.h.win32",
--- 88,96 ----
"-e 's/#define PG_VERSION \".*\"/#define PG_VERSION \"$fullversion\"/' " .
"-e 's/#define PG_VERSION_NUM .*/#define PG_VERSION_NUM $padnumericversion/'");
+ sed_file("src/interfaces/libpq/fe-misc.c",
+ "-e 's/#define LOCAL_PG_VERSION_NUM .*/#define LOCAL_PG_VERSION_NUM $padnumericversion/'");
+
sed_file("src/interfaces/libpq/libpq.rc.in",
"-e 's/FILEVERSION [0-9]*,[0-9]*,[0-9]*,0/FILEVERSION $major1,$major2,$numericminor,0/' " .
"-e 's/PRODUCTVERSION [0-9]*,[0-9]*,[0-9]*,0/PRODUCTVERSION $major1,$major2,$numericminor,0/' " .
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: [GENERAL] queriing the version of libpq
@ 2010-12-16 16:00 Dmitriy Igrishin <dmitigr@gmail.com>
parent: Magnus Hagander <magnus@hagander.net>
1 sibling, 0 replies; 18+ messages in thread
From: Dmitriy Igrishin @ 2010-12-16 16:00 UTC (permalink / raw)
To: Magnus Hagander <magnus@hagander.net>; +Cc: Massa, Harald Armin <chef@ghum.de>; PostgreSQL-development <pgsql-hackers@postgresql.org>
Magnus, thats great ! And name PQlibVersion is correct ! Thanks.
2010/12/16 Magnus Hagander <magnus@hagander.net>
> On Tue, Dec 14, 2010 at 17:56, Massa, Harald Armin <chef@ghum.de> wrote:
> >>> My question: Which way is available to query the linked libpq version?
> >
> >> But it does outline that fact that it wouldn't suck to have a >function
> in libpq returning the version so that application can >check this at
> runtime - clearly it would also be useful when >being linked "through"
> something like psycopg2.
> >
> > did there something happen?
>
> Stuck in a local git branch. I've rebased on current and added docs,
> see attachment.
>
> (moving to hackers as well)
>
> --
> Magnus Hagander
> Me: http://www.hagander.net/
> Work: http://www.redpill-linpro.com/
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>
>
--
// Dmitriy.
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: [GENERAL] queriing the version of libpq
@ 2010-12-16 16:07 Tom Lane <tgl@sss.pgh.pa.us>
parent: Magnus Hagander <magnus@hagander.net>
1 sibling, 1 reply; 18+ messages in thread
From: Tom Lane @ 2010-12-16 16:07 UTC (permalink / raw)
To: Magnus Hagander <magnus@hagander.net>; +Cc: Massa, Harald Armin <chef@ghum.de>; PostgreSQL-development <pgsql-hackers@postgresql.org>
Magnus Hagander <magnus@hagander.net> writes:
> But it does outline that fact that it wouldn't suck to have a >function in libpq returning the version so that application can >check this at runtime - clearly it would also be useful when >being linked "through" something like psycopg2.
> Stuck in a local git branch. I've rebased on current and added docs,
> see attachment.
Ick. Please get rid of that extra version number. There is no reason
not to use PG_VERSION_NUM. The documentation needs further thought too:
grammar needs work, and the format of the result value is unspecified.
But perhaps we should first recheck the premise. Exactly how will this
function be useful? I don't believe it's usable in the form implied by
the documentation, namely
if (PQlibVersion() >= something)
... call PQspiffyNewFunction() ...
else
... do something else ...
because if you're trying to link against an older libpq, the link will
fail before you ever get to execute. So let's have a less implausible
use-case please.
regards, tom lane
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: [GENERAL] queriing the version of libpq
@ 2010-12-16 16:12 Magnus Hagander <magnus@hagander.net>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 18+ messages in thread
From: Magnus Hagander @ 2010-12-16 16:12 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Massa, Harald Armin <chef@ghum.de>; PostgreSQL-development <pgsql-hackers@postgresql.org>
On Thu, Dec 16, 2010 at 17:07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Magnus Hagander <magnus@hagander.net> writes:
>> But it does outline that fact that it wouldn't suck to have a >function in libpq returning the version so that application can >check this at runtime - clearly it would also be useful when >being linked "through" something like psycopg2.
>
>> Stuck in a local git branch. I've rebased on current and added docs,
>> see attachment.
>
> Ick. Please get rid of that extra version number. There is no reason
> not to use PG_VERSION_NUM. The documentation needs further thought too:
> grammar needs work, and the format of the result value is unspecified.
Gah. i was thinking "need to avoid pulling in pg_config.h since it's
exposed to clients".. But that's only the header. D'uh. Will fix.
> But perhaps we should first recheck the premise. Exactly how will this
> function be useful? I don't believe it's usable in the form implied by
> the documentation, namely
>
> if (PQlibVersion() >= something)
> ... call PQspiffyNewFunction() ...
> else
> ... do something else ...
>
> because if you're trying to link against an older libpq, the link will
> fail before you ever get to execute. So let's have a less implausible
> use-case please.
Look back at the very start of the thread.
Detecting behavior changes (in this case with bytea encoding).
The other one would be if there are options to a call that can be
different. For example, knowing which options you can pass to
PQconnect() without getting an error. (Yes, you can manually call
PQconninfoParse() and check it out, but that's a lot uglier IMO).
And it *could* be used in exactly the case you're outlining as long as
you load the function dynamically. Which could most definitely be
useful for a *driver* to be able to do - and I'm sure some programs as
well.
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: [GENERAL] queriing the version of libpq
@ 2010-12-16 16:13 Tom Lane <tgl@sss.pgh.pa.us>
parent: Magnus Hagander <magnus@hagander.net>
1 sibling, 1 reply; 18+ messages in thread
From: Tom Lane @ 2010-12-16 16:13 UTC (permalink / raw)
To: Magnus Hagander <magnus@hagander.net>; +Cc: Massa, Harald Armin <chef@ghum.de>; PostgreSQL-development <pgsql-hackers@postgresql.org>
Magnus Hagander <magnus@hagander.net> writes:
> On Thu, Dec 16, 2010 at 17:07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> because if you're trying to link against an older libpq, the link will
>> fail before you ever get to execute. So let's have a less implausible
>> use-case please.
> Look back at the very start of the thread.
OK, but let's document those examples instead.
regards, tom lane
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: [GENERAL] queriing the version of libpq
@ 2010-12-16 16:22 Andrew Chernow <ac@esilo.com>
parent: Magnus Hagander <magnus@hagander.net>
1 sibling, 0 replies; 18+ messages in thread
From: Andrew Chernow @ 2010-12-16 16:22 UTC (permalink / raw)
To: Magnus Hagander <magnus@hagander.net>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Massa, Harald Armin <chef@ghum.de>; PostgreSQL-development <pgsql-hackers@postgresql.org>
>
> And it *could* be used in exactly the case you're outlining as long as
> you load the function dynamically.
Detecting the presence of a function does not require a version number.
If the symbol is in the library, use it.
The only reason the version number would come into play is if you were
attempting to detect behavior differences.
--
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: [GENERAL] queriing the version of libpq
@ 2010-12-20 15:48 Magnus Hagander <magnus@hagander.net>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 18+ messages in thread
From: Magnus Hagander @ 2010-12-20 15:48 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Massa, Harald Armin <chef@ghum.de>; PostgreSQL-development <pgsql-hackers@postgresql.org>
On Thu, Dec 16, 2010 at 17:13, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Magnus Hagander <magnus@hagander.net> writes:
>> On Thu, Dec 16, 2010 at 17:07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> because if you're trying to link against an older libpq, the link will
>>> fail before you ever get to execute. So let's have a less implausible
>>> use-case please.
>
>> Look back at the very start of the thread.
>
> OK, but let's document those examples instead.
Something like this better?
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
Attachments:
libpq_version.diff (text/x-patch, 3.1K) download
diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml
index c502439..a776df4 100644
--- a/doc/src/sgml/libpq.sgml
+++ b/doc/src/sgml/libpq.sgml
@@ -5359,6 +5359,50 @@ void *PQresultAlloc(PGresult *res, size_t nBytes);
</listitem>
</varlistentry>
+ <varlistentry id="libpq-pqlibversion">
+ <term>
+ <function>PQlibVersion</function>
+ <indexterm>
+ <primary>PQlibVersion</primary>
+ <seealso>PQserverVersion</seealso>
+ </indexterm>
+ </term>
+
+ <listitem>
+ <para>
+ Return the version of <productname>libpq</> that is being used.
+<synopsis>
+int PQlibVersion(void);
+</synopsis>
+ </para>
+
+ <para>
+ The result value of this function can be used to determine, at
+ runtime, if a specific functionality is available in the currently
+ loaded version of libpq. Examples of this include whether specific
+ connection options are available for <function>PQconnectdb</> and
+ the new <type>bytea</> encoding in PostgreSQL 9.0 that requires
+ libpq version 9.0 or later to work.
+ </para>
+
+ <para>
+ The number is formed by converting the major, minor, and revision
+ numbers into two-decimal-digit numbers and appending them together.
+ For example, version 9.1 will be returned as 90100, and version
+ 9.1.2 will be returned as 90102 (leading zeroes are not shown).
+ </para>
+
+ <note>
+ <para>
+ This function appeared in <productname>PostgreSQL</> version 9.1, so
+ it cannot be used to detect required functionality in earlier
+ versions, since linking to it will create a load time dependency
+ on version 9.1.
+ </para>
+ </note>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</sect1>
diff --git a/src/interfaces/libpq/exports.txt b/src/interfaces/libpq/exports.txt
index a6c73af..1af8df6 100644
--- a/src/interfaces/libpq/exports.txt
+++ b/src/interfaces/libpq/exports.txt
@@ -159,3 +159,4 @@ PQconnectdbParams 156
PQconnectStartParams 157
PQping 158
PQpingParams 159
+PQlibVersion 160
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index 24ab7cf..999f60b 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -66,6 +66,14 @@ static int pqSocketCheck(PGconn *conn, int forRead, int forWrite,
time_t end_time);
static int pqSocketPoll(int sock, int forRead, int forWrite, time_t end_time);
+/*
+ * PQlibVersion: return the libpq version number
+ */
+int
+PQlibVersion(void)
+{
+ return PG_VERSION_NUM;
+}
/*
* fputnbytes: print exactly N bytes to a file
diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h
index 271afed..6075ea8 100644
--- a/src/interfaces/libpq/libpq-fe.h
+++ b/src/interfaces/libpq/libpq-fe.h
@@ -547,6 +547,9 @@ extern int lo_export(PGconn *conn, Oid lobjId, const char *filename);
/* === in fe-misc.c === */
+/* Get the version of the libpq library in use */
+extern int PQlibVersion(void);
+
/* Determine length of multibyte encoded char at *s */
extern int PQmblen(const char *s, int encoding);
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: [GENERAL] queriing the version of libpq
@ 2010-12-22 13:26 Magnus Hagander <magnus@hagander.net>
parent: Magnus Hagander <magnus@hagander.net>
0 siblings, 0 replies; 18+ messages in thread
From: Magnus Hagander @ 2010-12-22 13:26 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Massa, Harald Armin <chef@ghum.de>; PostgreSQL-development <pgsql-hackers@postgresql.org>
On Mon, Dec 20, 2010 at 16:48, Magnus Hagander <magnus@hagander.net> wrote:
> On Thu, Dec 16, 2010 at 17:13, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Magnus Hagander <magnus@hagander.net> writes:
>>> On Thu, Dec 16, 2010 at 17:07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>>> because if you're trying to link against an older libpq, the link will
>>>> fail before you ever get to execute. So let's have a less implausible
>>>> use-case please.
>>
>>> Look back at the very start of the thread.
>>
>> OK, but let's document those examples instead.
>
> Something like this better?
I got some help from Bruce to look over the grammar in the docs (and
fix the broken ones), and have now applied and pushed this.
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
^ permalink raw reply [nested|flat] 18+ messages in thread
* Re: queriing the version of libpq
@ 2018-06-10 19:53 crbenesch <chris@beneschtech.com>
parent: Massa, Harald Armin <chef@ghum.de>
1 sibling, 0 replies; 18+ messages in thread
From: crbenesch @ 2018-06-10 19:53 UTC (permalink / raw)
To: pgsql-general
#include <pg_config.h>
/usr/include/pg_config-x86_64.h:#define PG_VERSION "9.6.9"
/usr/include/pg_config-x86_64.h:#define PG_VERSION_NUM 90609
/usr/include/pg_config-x86_64.h:#define PG_VERSION_STR "PostgreSQL 9.6.9 on
x86_64-redhat-linux-gnu, compiled by gcc (GCC) 7.3.1 20180303 (Red Hat
7.3.1-5), 64-bit"
I also have source for 8.4 and its there too.
--
Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
^ permalink raw reply [nested|flat] 18+ messages in thread
end of thread, other threads:[~2018-06-10 19:53 UTC | newest]
Thread overview: 18+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-10-05 07:33 queriing the version of libpq Massa, Harald Armin <chef@ghum.de>
2010-10-05 08:02 ` Magnus Hagander <magnus@hagander.net>
2010-12-14 16:56 ` Massa, Harald Armin <chef@ghum.de>
2010-12-16 15:56 ` Magnus Hagander <magnus@hagander.net>
2010-12-16 16:00 ` Dmitriy Igrishin <dmitigr@gmail.com>
2010-12-16 16:07 ` Tom Lane <tgl@sss.pgh.pa.us>
2010-12-16 16:12 ` Magnus Hagander <magnus@hagander.net>
2010-12-16 16:13 ` Tom Lane <tgl@sss.pgh.pa.us>
2010-12-20 15:48 ` Magnus Hagander <magnus@hagander.net>
2010-12-22 13:26 ` Magnus Hagander <magnus@hagander.net>
2010-12-16 16:22 ` Andrew Chernow <ac@esilo.com>
2018-06-10 19:53 ` crbenesch <chris@beneschtech.com>
2010-10-05 14:32 ` Greg Sabino Mullane <greg@turnstep.com>
2010-10-05 14:38 ` Magnus Hagander <magnus@hagander.net>
2010-10-07 09:23 ` Peter Eisentraut <peter_e@gmx.net>
2010-10-07 09:34 ` Devrim GÜNDÜZ <devrim@gunduz.org>
2010-10-07 15:07 ` A.M. <agentm@themactionfaction.com>
2010-10-20 23:26 ` Bruce Momjian <bruce@momjian.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox