Re: Trigger Function question

2023-07-11 Thread Lorusso Domenico
I've just finish to do the same thing. For my needs, I decided to create a table with the information I need for each view (yes I set trigger on view not on table). anyway, hstore is more performant rather than jsonb but both of them could treat NEW and OLD as hashmap (or associative array) Il g

Re: Trigger Function question

2023-07-10 Thread Christophe Pettus
> On Jul 10, 2023, at 11:46, DAVID ROTH wrote: > > Is there a way to get new.* into a jsonb column? The to_jsonb() function accepts a row type like NEW.*, and returns a JSONB object with the keys as column names.

Re: Trigger Function question

2023-07-10 Thread Marcos Pegoraro
> > Is there a way to get new.* into a jsonb column? > select json_object_agg(js.key, js.value) from json_each_text(row_to_json(new.*)) js Marcos

Re: Trigger Function question

2023-07-10 Thread DAVID ROTH
I saw your message about a "few" columns and missed the new.* notation. Is there a way to get new.* into a jsonb column? > On 07/10/2023 2:38 PM EDT Christophe Pettus wrote: > > > > On Jul 10, 2023, at 11:37, DAVID ROTH wrote: > > > > Thanks for the example. I have a test trigger now that do

Re: Trigger Function question

2023-07-10 Thread DAVID ROTH
I was hoping that NEW could be treated as a record or as an arrayy similar to pg_argv. > On 07/10/2023 2:31 PM EDT Christophe Pettus wrote: > > > > On Jul 10, 2023, at 11:29, DAVID ROTH wrote: > > > > I want to use a single trigger function to log multiple tables and the > > tables have di

Re: Trigger Function question

2023-07-10 Thread Christophe Pettus
> On Jul 10, 2023, at 11:37, DAVID ROTH wrote: > > Thanks for the example. I have a test trigger now that does that but my > application needs all of the columns. I'm not quite sure I understanding. Logging NEW.* and OLD.* *does* get all the columns, without having to specific query to fin

Re: Trigger Function question

2023-07-10 Thread DAVID ROTH
Thanks for the example. I have a test trigger now that does that but my application needs all of the columns. > On 07/10/2023 2:31 PM EDT Christophe Pettus wrote: > > > > On Jul 10, 2023, at 11:29, DAVID ROTH wrote: > > > > I want to use a single trigger function to log multiple tables and

Re: Trigger Function question

2023-07-10 Thread Christophe Pettus
> On Jul 10, 2023, at 11:29, DAVID ROTH wrote: > > I want to use a single trigger function to log multiple tables and the tables > have different columns. I can get the names of the columns from the catalog. > But I have not been able to figure out how to get NEW.x when x is not known > u

Re: Trigger Function question

2023-07-10 Thread DAVID ROTH
I want to use a single trigger function to log multiple tables and the tables have different columns. I can get the names of the columns from the catalog. But I have not been able to figure out how to get NEW.x when x is not known until run time. > On 07/10/2023 2:23 PM EDT Christophe Pettus

Re: Trigger Function question

2023-07-10 Thread Christophe Pettus
> On Jul 10, 2023, at 11:20, DAVID ROTH wrote: > > In a trigger function, is there a way to get a list of all of the columns in > the triggering table? You can get the table that the trigger fired on with TG_TABLE_SCHEMA and TG_TABLE_NAME, and then query the system catalogs to get a list of

Trigger Function question

2023-07-10 Thread DAVID ROTH
In a trigger function, is there a way to get a list of all of the columns in the triggering table? I want to be able to use a single trigger function with multiple tables. Thanks