Re: Running CREATE only on certain Postgres versions

From: David Johnston <polobo(at)yahoo(dot)com>
To: Robert James <srobertjames(at)gmail(dot)com>
Cc: Igor Neyman <ineyman(at)perceptron(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Running CREATE only on certain Postgres versions
Date: 2012-09-25 01:40:23
Message-ID: 811F6430-4B7B-4833-958A-086C2DBC3CE4@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Server parameter: server_version_num

http://www.postgresql.org/docs/9.2/interactive/runtime-config-preset.html

David J.

On Sep 24, 2012, at 21:23, Robert James <srobertjames(at)gmail(dot)com> wrote:

> Unfortunately, SELECT VERSION() gives a long text string - parsing out
> the version isn't reliable.
>
> So, we can reduce my question to a simpler question: What's the best
> way to determine if postgres is running > version x?
>
> Or, what's the best way to determine the exact version number
> programatically (ie not just a long string)
>
> On 9/24/12, Igor Neyman <ineyman(at)perceptron(dot)com> wrote:
>>> -----Original Message-----
>>> From: Robert James [mailto:srobertjames(at)gmail(dot)com]
>>> Sent: Monday, September 24, 2012 9:33 AM
>>> To: Postgres General
>>> Subject: Running CREATE only on certain Postgres versions
>>>
>>> I have some code which creates a function in Postgres, taken from
>>> http://wiki.postgresql.org/wiki/Array_agg .
>>>
>>> DROP AGGREGATE IF EXISTS array_agg(anyelement); CREATE AGGREGATE
>>> array_agg(anyelement) ( SFUNC=array_append, STYPE=anyarray,
>>> INITCOND='{}'
>>> );
>>>
>>> The function was added in 8.4, and so the code fails when run on 8.4 or
>>> higher.
>>>
>>> How can I make the code cross-version compatible? For instance, how
>>> can I tell it to check the version, and only run if 8.3 or lower? Or
>>> another way to make it cross-version?
>>
>> Find your PG version with:
>> SELECT version();
>>
>> and continue accordingly...
>>
>> Regards,
>> Igor Neyman
>>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message ichBinRene 2012-09-25 03:27:56 plpython2u not getting any output -> on independent script I get the desired output
Previous Message Robert James 2012-09-25 01:23:49 Re: Running CREATE only on certain Postgres versions