Re: Create event triger

From: Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: jaryszek(at)gmail(dot)com, Guillaume Lelarge <guillaume(at)lelarge(dot)info>, PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Create event triger
Date: 2018-07-11 08:29:57
Message-ID: CAD3a31XR4Lkeib3v=jhL1Ctdg8c7atKQeAkoioV2ROpCBE2kPw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jul 10, 2018 at 5:45 PM Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
wrote:

> select add_trigger('trg_test');
>
> test=> \d trg_test
>
> Table "public.trg_test"
>
>
> Column | Type | Collation | Nullable | Default
>
>
> --------+-------------------+-----------+----------+---------
>
>
> id | integer | | |
>
>
> fld_1 | character varying | | |
>
>
> Triggers:
>
>
> trg_test_change AFTER UPDATE ON trg_test FOR EACH STATEMENT EXECUTE
> PROCEDURE ts_update()
>
>
To take this a step further, if you really have a lot of tables and want to
do it automatically, you could do something like this:

SELECT table_name,add_trigger(table_name) FROM
information_schema.tables WHERE table_schema='public';

This assumes that you want to add the trigger to _all_ your tables, and
that you haven't made use of schemas and so your tables are all in the
public schema.
If that's not the case, you could adjust accordingly. It would be safest
to just pull the table names first, make sure the list is what you want,
and then run with the add_trigger. So start with this:

SELECT table_name FROM information_schema.tables WHERE table_schema='public';

and if the list of tables is what you want, then run with the add_trigger
included.

Cheers,
Ken

--
AGENCY Software
A Free Software data system
By and for non-profits
*http://agency-software.org/ <http://agency-software.org/>*
*https://demo.agency-software.org/client
<https://demo.agency-software.org/client>*
ken(dot)tanzer(at)agency-software(dot)org
(253) 245-3801

Subscribe to the mailing list
<agency-general-request(at)lists(dot)sourceforge(dot)net?body=subscribe> to
learn more about AGENCY or
follow the discussion.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Raymond O'Donnell 2018-07-11 09:51:21 Re: Open Source tool to deploy/promote PostgreSQL DDL
Previous Message Thomas Kellerer 2018-07-11 07:08:13 Re: Open Source tool to deploy/promote PostgreSQL DDL