Re: queriing the version of libpq

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: "Massa, Harald Armin" <chef(at)ghum(dot)de>
Cc: PGSQL Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: queriing the version of libpq
Date: 2010-10-05 08:02:47
Message-ID: AANLkTi=cPLuPn=WDf7r9APz632Pf3qyM8BbEKt5sA0Pd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Tue, Oct 5, 2010 at 09:33, Massa, Harald Armin <chef(at)ghum(dot)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/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mike Christensen 2010-10-05 08:08:26 Windows 2008/IIS cannot connect to Postgres 9.0
Previous Message Sairam Krishnamurthy 2010-10-05 07:52:00 Re: Having two simultaneous and similar database

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2010-10-05 08:06:50 Re: OUTER keyword
Previous Message Massa, Harald Armin 2010-10-05 07:33:44 queriing the version of libpq