Skip site navigation (1) Skip section navigation (2)

Re: [PATCHES] New variable server_version_num

From: David Fetter <david(at)fetter(dot)org>
To: Greg Sabino Mullane <greg(at)turnstep(dot)com>
Cc: PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>,PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: [PATCHES] New variable server_version_num
Date: 2006-08-28 02:09:40
Message-ID: 20060828020940.GK3636@fetter.org (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-hackerspgsql-patches
On Sat, Jul 29, 2006 at 09:14:16PM -0400, Greg Sabino Mullane wrote:
> Today on IRC David Fetter and some others were discussing version
> numbers and we realized that although libpq now provides the version of
> Postgres as a number, this is still a wheel that is being reinvented by
> apps many times over, as it is not available any other way. Hence, a
> small patch to provide a new variable "server_version_num", which is
> almost the same as "server_version" but uses the handy PG_VERSION_NUM
> which allows apps to do things like if ($version >= 80200) without
> having to parse apart the value of server_version themselves.

Here's an SQL function which does the same thing.  I've had it tested
back through 7.4x, and it should work back to the 7.3 series, although
I haven't tested it there.  Thanks to Andrew of Supernews for the
short version :)

SELECT
    sum(
        substring(
            split_part(
                current_setting(
                    'server_version'
                ),
                '.'
            ,
            i
        )
        FROM
        '^[[:digit:]]+'
    )::integer * 10^(6-i*2) ) AS server_version_integer
FROM (
    SELECT 1
UNION ALL
    SELECT 2
UNION ALL
    SELECT 3
) AS s(i);

Cheers,
D
-- 
David Fetter <david(at)fetter(dot)org> http://fetter.org/
phone: +1 415 235 3778        AIM: dfetter666
                              Skype: davidfetter

Remember to vote!

In response to

pgsql-hackers by date

Next:From: AgentMDate: 2006-08-28 02:49:32
Subject: Re: jabber.postgresql.org is up
Previous:From: Chahine HamilaDate: 2006-08-28 01:47:14
Subject: Re: integration of pgcluster into postgresql

pgsql-patches by date

Next:From: Alvaro HerreraDate: 2006-08-28 02:54:54
Subject: Another VPATH patch for ecpg
Previous:From: Bruce MomjianDate: 2006-08-28 01:22:18
Subject: Re: Adding fulldisjunctions to the contrib

pgsql-general by date

Next:From: AgentMDate: 2006-08-28 02:49:32
Subject: Re: jabber.postgresql.org is up
Previous:From: Jasbinder BaliDate: 2006-08-28 01:41:39
Subject: Re: Shared Objects (Dynamic loading)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group