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

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Reply via email to