pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Igor Korot <ikorot01@gmail.com>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: How to watch for schema changes
Date: Thu, 5 Jul 2018 10:02:18 -0700
Message-ID: <e2c680bc-5f13-b1af-676d-ff88e2bf4f6c@aklaver.com> (raw)
In-Reply-To: <CA+FnnTwt=DfOH=HggP9tw1hj++eBymBeD4Rp2-w5JxeFjh5pDg@mail.gmail.com>
References: <CA+FnnTxqScf6mDw_7HLMfu7YTagPrsYUw-bc=OKsBQ0TqprvEA@mail.gmail.com>
	<d17c5c84-2988-8536-21c4-17ce9a9ef18c@aklaver.com>
	<CA+FnnTyNceWUR7+rDdOgbNfzM-ZyY-YQiBG8f9ATiceBCOs8qw@mail.gmail.com>
	<7fc929ec-8e34-5824-6511-d1dd1188434f@aklaver.com>
	<CA+FnnTzkaY39==wd=ZG-GqHY-pmaroTxC1oi0yDnQ10_rFB4mA@mail.gmail.com>
	<CAKFQuwZsZvOj-XH8APjzfteD+-7XHE+tVunLLvqXgd76W0fu2w@mail.gmail.com>
	<CA+FnnTwt=DfOH=HggP9tw1hj++eBymBeD4Rp2-w5JxeFjh5pDg@mail.gmail.com>

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.g.johnston@gmail.com> wrote:
>> On Tue, Jul 3, 2018 at 11:41 AM, Igor Korot <ikorot01@gmail.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.klaver@aklaver.com




view thread (52+ messages)  latest in thread

Message-ID: <e2c680bc-5f13-b1af-676d-ff88e2bf4f6c@aklaver.com>
Permalink:  ../e2c680bc-5f13-b1af-676d-ff88e2bf4f6c@aklaver.com/
Also on:    postgresql.org/message-id/e2c680bc-5f13-b1af-676d-ff88e2bf4f6c@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, ikorot01@gmail.com, david.g.johnston@gmail.com
  Subject: Re: How to watch for schema changes
  In-Reply-To: <e2c680bc-5f13-b1af-676d-ff88e2bf4f6c@aklaver.com>
  References: <CA+FnnTxqScf6mDw_7HLMfu7YTagPrsYUw-bc=OKsBQ0TqprvEA@mail.gmail.com> <d17c5c84-2988-8536-21c4-17ce9a9ef18c@aklaver.com> <CA+FnnTyNceWUR7+rDdOgbNfzM-ZyY-YQiBG8f9ATiceBCOs8qw@mail.gmail.com> <7fc929ec-8e34-5824-6511-d1dd1188434f@aklaver.com> <CA+FnnTzkaY39==wd=ZG-GqHY-pmaroTxC1oi0yDnQ10_rFB4mA@mail.gmail.com> <CAKFQuwZsZvOj-XH8APjzfteD+-7XHE+tVunLLvqXgd76W0fu2w@mail.gmail.com> <CA+FnnTwt=DfOH=HggP9tw1hj++eBymBeD4Rp2-w5JxeFjh5pDg@mail.gmail.com> <e2c680bc-5f13-b1af-676d-ff88e2bf4f6c@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox