From: | Igor Neyman <ineyman(at)perceptron(dot)com> |
---|---|
To: | Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>, Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com> |
Cc: | David Johnston <polobo(at)yahoo(dot)com>, Robert James <srobertjames(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Running CREATE only on certain Postgres versions |
Date: | 2012-09-25 15:39:41 |
Message-ID: | A76B25F2823E954C9E45E32FA49D70EC08EB57AC@mail.corp.perceptron.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
> -----Original Message-----
> From: Daniele Varrazzo [mailto:daniele(dot)varrazzo(at)gmail(dot)com]
> Sent: Tuesday, September 25, 2012 11:26 AM
> To: Adrian Klaver
> Cc: David Johnston; Robert James; Igor Neyman; Postgres General
> Subject: Re: [GENERAL] Running CREATE only on certain Postgres versions
>
> On Tue, Sep 25, 2012 at 3:47 PM, Adrian Klaver
> <adrian(dot)klaver(at)gmail(dot)com> wrote:
>
> > To elaborate:
> > test=> SELECT current_setting('server_version_num');
> > current_setting
> > -----------------
> > 90009
>
> Yes, but knowing that, how does he run a statement only if version e.g.
> >= 80400? Is there a better way than the proposed create/call/drop
> function before PG 9.0? (since 9.0 there is the DO statement).
>
> -- Daniele
For PG versions prior to 9.0 (without DO statement) I wrote and use extensively this little function:
CREATE OR REPLACE FUNCTION exec_pgplsql_block(exec_string text)
RETURNS BOOLEAN
AS $THIS$
DECLARE lRet BOOLEAN;
BEGIN
EXECUTE 'CREATE OR REPLACE FUNCTION any_block()
RETURNS VOID
AS $BODY$ ' || exec_string || ' $BODY$LANGUAGE PLPGSQL;' ;
PERFORM any_block();
RETURN TRUE;
END;
$THIS$LANGUAGE PLPGSQL;
which accepts as a parameter ("exec_string") any "anonymous" PlPgSQL block (what DO does in later versions),
creates a function with this PlPgSQL block as a body, and executes it.
Regards,
Igor Neyman
From | Date | Subject | |
---|---|---|---|
Next Message | hartrc | 2012-09-25 16:09:11 | PostgreSQL data loads - turn off WAL |
Previous Message | hubert depesz lubaczewski | 2012-09-25 15:32:57 | Re: unique constraint with significant nulls? |