> -----Original Message-----
> From: Daniele Varrazzo [mailto:daniele.varrazzo@gmail.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.klaver@gmail.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