Re: Advice request : simultaneous function/data updates on many databases

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Rory Campbell-Lange <rory(at)campbell-lange(dot)net>
Cc: Guyren Howe <guyren(at)gmail(dot)com>, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Advice request : simultaneous function/data updates on many databases
Date: 2020-03-04 22:58:01
Message-ID: CAKFQuwZh-2pfr73XNUXg9CJtSDaVbiTOJYF4Dbre_6vs-JjcMA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Mar 4, 2020 at 3:55 PM David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
wrote:

> On Wed, Mar 4, 2020 at 3:48 PM Rory Campbell-Lange <
> rory(at)campbell-lange(dot)net> wrote:
>
>> Any thoughts on how to wrap pl/pgsql function dropping and recreation code
>> within a wrapper pl/pgsql function?
>
>
> Not endorsing this but dynamic SQL works just fine (though can get hard to
> read). Use format() and EXECUTE ... USING liberally.
>
>
Or, more readable depending upon your trust level:

INSERT INTO dynamic_codes VALUES (1, 'DROP FUNCTION ...');

CREATE FUNCTION execute_dynamic(code_id int)
AS $$
sql_cmd := (SELECT val FROM dynamic_codes WHERE id = code_id);
EXECUTE sql_cmd;
$$;

SELECT execute_dynamic(1);

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message stan 2020-03-04 23:21:35 Determining the type of an obkect in plperl
Previous Message David G. Johnston 2020-03-04 22:55:25 Re: Advice request : simultaneous function/data updates on many databases