Re: Version Number Function?

From: "David E(dot) Wheeler" <david(at)kineticode(dot)com>
To: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Version Number Function?
Date: 2008-10-14 15:33:39
Message-ID: B2B21B77-B95C-44D4-A5FB-55B8F3EA67EF@kineticode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Well, the C version I borrowed from dumpitils seems to work great. Any
reason I shouldn't stay with that?

Best,

David

Sent from my iPhone

On Oct 14, 2008, at 7:44, Hannu Krosing <hannu(at)2ndQuadrant(dot)com> wrote:

> On Sun, 2008-10-12 at 14:39 -0700, David E. Wheeler wrote:
>> On Oct 12, 2008, at 14:11, Tom Lane wrote:
>>
>>> You'd have to parse the result of version().
>>
>> As I figured. This is what I'm trying:
>
> if performance is not critical, then you could use this:
>
> hannu=# create or replace function pg_version_num() returns int
> language
> SQL as $$
> select
> 10000 *
> cast(substring(version()
> from
> '^PostgreSQL +([0-9]+)[.][0-9]+[.][0-9]+ +') as int)
> +
> 100 *
> cast(substring(version()
> from
> '^PostgreSQL +[0-9]+[.]([0-9]+)[.][0-9]+ +') as int)
> +
> cast(substring(version()
> from
> '^PostgreSQL +[0-9]+[.][0-9]+[.]([0-9]+) +') as int);
> $$;
> CREATE FUNCTION
>
> hannu=# select pg_version_num();
> pg_version_num
> ----------------
> 80303
> (1 row)
>
>> pg_version_num(PG_FUNCTION_ARGS)
>> {
>> #ifdef PG_VERSION_NUM
>> PG_RETURN_INT32(PG_VERSION_NUM);
>> #else
>> /* Code borrowed from dumputils.c. */
>> int cnt;
>> int vmaj,
>> vmin,
>> vrev;
>>
>> cnt = sscanf(PG_VERSION, "%d.%d.%d", &vmaj, &vmin, &vrev);
>>
>> if (cnt < 2)
>> return -1;
>>
>> if (cnt == 2)
>> vrev = 0;
>>
>> PG_RETURN_INT32( (100 * vmaj + vmin) * 100 + vrev );
>> #endif
>>
>> Best,
>>
>> David
>>
>>
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dave Page 2008-10-14 15:42:46 Re: 8.3 .4 + Vista + MingW + initdb = ACCESS_DENIED
Previous Message Magnus Hagander 2008-10-14 15:20:09 Re: 8.3 .4 + Vista + MingW + initdb = ACCESS_DENIED