Re: How to watch for schema changes

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Igor Korot <ikorot01(at)gmail(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to watch for schema changes
Date: 2018-07-05 17:02:18
Message-ID: e2c680bc-5f13-b1af-676d-ff88e2bf4f6c@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 07/05/2018 08:40 AM, Igor Korot wrote:
> Hi, David,
>
> On Tue, Jul 3, 2018 at 1:46 PM, David G. Johnston
> <david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
>> On Tue, Jul 3, 2018 at 11:41 AM, Igor Korot <ikorot01(at)gmail(dot)com> wrote:
>>>
>>>
>>> I presume threre is a query which check for the function/trigger
>>> existence? Something like:
>>>
>>> IF NOT EXIST(SELECT * FROM ) CREATE OR REPLACE FUNCTION....;
>>
>>
>> CREATE OR REPLACE is how you re-create a function that (whose
>> name/signature) might already exist; CREATE already assumes one doesn't
>> exist.
>
> Why do I need to re-create a function with exactly the same name and body

If you use CREATE OR REPLACE FUNCTION it will do just that each time you
call it. Seems like overkill to me. See below for another way.

> Can't I just check if such function exists?

Something like this:

SELECT
count(*)
FROM
pg_proc AS proc
JOIN
pg_namespace AS ns
ON
proc.pronamespace = ns.oid
WHERE
ns.nspname='public' -- Function schema
AND
proname = 'tag_rcv_undo' -- Function name
;

>
> Thank you.
>
>>
>> David J.
>>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Igor Korot 2018-07-05 17:07:01 Re: How to watch for schema changes
Previous Message David G. Johnston 2018-07-05 17:02:07 Re: As a table owner, can I grant "grant" ?