Re: How to check the postgresql version

From: Joe Conway <mail(at)joeconway(dot)com>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: Ruey-Lung Hsiao <rlhsiao(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: How to check the postgresql version
Date: 2004-11-21 15:38:35
Message-ID: 41A0B67B.3020406@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Neil Conway wrote:
> Ruey-Lung Hsiao wrote:
>> My problem is: I can't find a way to compare strings in C
>> preprocessor directive since PG_VERSION is defined as something like
>> "7.4.3" or "7.4.6".
>
> You could try using CATALOG_VERSION_NO in src/include/catversion.h as a
> substitute for the version number.

Along those lines, this is what I've been using in PL/R:

#if (CATALOG_VERSION_NO <= 200211021)
#define PG_VERSION_73_COMPAT
#elif (CATALOG_VERSION_NO <= 200310211)
#define PG_VERSION_74_COMPAT
#else
#define PG_VERSION_80_COMPAT
#endif

I wasn't following this thread earlier, but if you need to distinguish
between, for example, 7.4.3 and 7.4.6, the above won't help. If you just
need major Postgres version, it works well.

> I think it would probably be a good idea to add a PG_VERSION-workalike
> that is more amenable to use with cpp, though.

I agree. As an example, here's how it's done for R:

/*
* R version is calculated thus:
* Maj * 65536 + Minor * 256 + Build * 1
* So:
* version 1.8.0 results in:
* (1 * 65536) + (8 * 256) + (0 * 1) == 67584
* version 1.9.0 results in:
* (1 * 65536) + (9 * 256) + (0 * 1) == 67840
*/

Joe

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Hallgren 2004-11-21 15:55:37 Preventing some SQL commands
Previous Message Andrew Dunstan 2004-11-21 12:12:35 Re: OpenBSD/Sparc status