From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Igor Korot <ikorot01@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: How to watch for schema changes
Date: Mon, 3 Dec 2018 09:59:22 -0800
Message-ID: <4316b506-95d0-59b2-7857-5ae896e07e60@aklaver.com> (raw)
In-Reply-To: <CA+FnnTyx15GbSKvF8NP_eyn2BTepk6x6fRubwgnwRy283=dw6g@mail.gmail.com>
References: <CA+FnnTxqScf6mDw_7HLMfu7YTagPrsYUw-bc=OKsBQ0TqprvEA@mail.gmail.com>
<d17c5c84-2988-8536-21c4-17ce9a9ef18c@aklaver.com>
<CA+FnnTwWkSixK66ZiLzrdod7hfHkpp0okKFJAnFE8bfBhtaAQQ@mail.gmail.com>
<53538bab-5f26-247d-15bf-94785fdfb252@aklaver.com>
<CA+FnnTzwLRxVU-2iGXGnDyqTcyybYwc1vFFcsfrE=PapaqgN+Q@mail.gmail.com>
<761d4f03-08f4-e354-9cc0-d3cc5d0319c4@aklaver.com>
<CA+FnnTyx15GbSKvF8NP_eyn2BTepk6x6fRubwgnwRy283=dw6g@mail.gmail.com>
On 12/3/18 9:53 AM, Igor Korot wrote:
>> So event triggers are associated with
>> events(www.postgresql.org/docs/9.6/event-trigger-matrix.html) in a
>> particular database. A rough description is that they are triggers on
>> changes to the system catalogs.
>> You could, I guess, create and drop them for each connection. To me it
>> would seem more efficient to create them once. You then have the choice
>> of leaving them running or using the ALTER command I posted previously
>> to ENABLE/DISABLE them.
>
> OK, so how do I do it?
> There is no "CREATE EVENT TRIGGER IF NOT EXIST".
>
> As I say - I'm trying to make it work from both ODBC and libpq
> connection (one at a time)
Why? Just create the trigger once in a script. Event triggers are an
attribute of the database and stay with it until they are dropped. If
you want to turn then on and off use the ALTER EVENT TRIGGER
ENABLE/DISABLE. If you insist on recreating them on each connection then:
https://www.postgresql.org/docs/10/sql-dropeventtrigger.html
DROP EVENT TRIGGER [ IF EXISTS ] name [ CASCADE | RESTRICT ]
CREATE EVENT TRIGGER ...
>
>>
>>>
>>> Now the other question is - how to make it work?
>>> I can write the function code, compile it and place in the folder
>>> where my executable is (or it should be in some postgreSQL dir?) and
>>> then executing above code
>>> will be enough. Is this correct?
>
> Also - what about this?
>
> And why did you say that saving the SQL commend is not a good idea.
>
> What's better?
See above.
>
> Thank you.
>
>>>
>>>>
>>>>>
>>>>> And then in my C++ code I will continuously query this temporary table.
>>>>
>>>> Why a temporary table? They are session specific and if the session
>>>> aborts prematurely you will lose the information.
>>>
>>> Is there a better alternative?
>>>
>>> Thank you.
>>>
>>>>
>>>>>
>>>>> Or there is a better alternative on the algorithm?
>>>>>
>>>>> Thank you.
>>>>>
>>>>>>>>
>>>>>>> Thank you.
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Adrian Klaver
>>>>>> adrian.klaver@aklaver.com
>>>>>
>>>>
>>>>
>>>> --
>>>> Adrian Klaver
>>>> adrian.klaver@aklaver.com
>>>
>>
>>
>> --
>> Adrian Klaver
>> adrian.klaver@aklaver.com
--
Adrian Klaver
adrian.klaver@aklaver.com
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
Subject: Re: How to watch for schema changes
In-Reply-To: <4316b506-95d0-59b2-7857-5ae896e07e60@aklaver.com>
References: <CA+FnnTxqScf6mDw_7HLMfu7YTagPrsYUw-bc=OKsBQ0TqprvEA@mail.gmail.com> <d17c5c84-2988-8536-21c4-17ce9a9ef18c@aklaver.com> <CA+FnnTwWkSixK66ZiLzrdod7hfHkpp0okKFJAnFE8bfBhtaAQQ@mail.gmail.com> <53538bab-5f26-247d-15bf-94785fdfb252@aklaver.com> <CA+FnnTzwLRxVU-2iGXGnDyqTcyybYwc1vFFcsfrE=PapaqgN+Q@mail.gmail.com> <761d4f03-08f4-e354-9cc0-d3cc5d0319c4@aklaver.com> <CA+FnnTyx15GbSKvF8NP_eyn2BTepk6x6fRubwgnwRy283=dw6g@mail.gmail.com> <4316b506-95d0-59b2-7857-5ae896e07e60@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