Re: [PATCH] Add pg_get_trigger_ddl() to retrieve the CREATE TRIGGER statement - Mailing list pgsql-hackers

From Philip Alger
Subject Re: [PATCH] Add pg_get_trigger_ddl() to retrieve the CREATE TRIGGER statement
Date
Msg-id CAPXBC8++u+mYVDMDAeJ=KYPWYbOdonL-7jJOE31U1j4F6W35vg@mail.gmail.com
Whole thread Raw
In response to Re: [PATCH] Add pg_get_trigger_ddl() to retrieve the CREATE TRIGGER statement  (Josef Šimánek <josef.simanek@gmail.com>)
List pgsql-hackers
Hello Hackers,

I was thinking about the patch a little more, and I think some people may want the pretty formatted option. 

I was going to create another patch for pg_get_triggerdef to add that functionality, like pg_get_functiondef and pg_get_viewdef. but I think it will break it since pg_get_triggerdef is used for the \d table command and requires the trigger to be printed as one line. The idea I had was to create another function called pg_get_triggerdef_worker_formatted(oid) that takes the OID and behaves the same way as pg_get_triggerdef_worker but adds the pretty formatting capability using appendContextKeyword() and the PRETTYFLAG_INDENT

You might be saying, "there already is a pretty printing capability for pg_get_triggerdef". No, it just removes the schema name. What I am proposing is similar to the output of pg_get_functiondef or pg_get_viewdef. The proposal is this, I can add the pg_get_triggerdef_worker_formatted function and refactor pg_get_trigger_ddl so that we get a formatted output like this:

 CREATE TRIGGER trg BEFORE INSERT
     ON main_table
     FOR EACH STATEMENT
     EXECUTE FUNCTION trgf()

versus one line:

  CREATE TRIGGER trg BEFORE INSERT ON main_table FOR EACH STATEMENT EXECUTE FUNCTION trgf();

The function pg_get_triggerdef_worker_formatted will receive an OID as a parameter, while pg_get_trigger_ddl will remain the same taking the regclass and trigger name as parameters.

The other proposal is to leave it as it is.

--
Best,
Phil Alger

pgsql-hackers by date:

Previous
From: Alexander Korotkov
Date:
Subject: Re: Implement waiting for wal lsn replay: reloaded
Next
From: Corey Huinker
Date:
Subject: Re: Extended Statistics set/restore/clear functions.