Re: Trigger usecase

2024-07-30 Thread Alban Hertroys
> On 30 Jul 2024, at 17:16, sud wrote: > > Hello, > > We have a streaming application (using apache flink and kafka) which > populates data in the tables of a postgres database version 15.4. > > Now while loading transactions data we also get some reference data > information from source (

Re: Trigger usecase

2024-07-30 Thread Adrian Klaver
On 7/30/24 13:28, David G. Johnston wrote: On Tue, Jul 30, 2024 at 11:46 AM sud > wrote: Not sure of the exact pros and cons, but we were following certain rules like , if it's business logic which needs to be implemented in Database, then it should not be

Re: Trigger usecase

2024-07-30 Thread David G. Johnston
On Tue, Jul 30, 2024 at 11:46 AM sud wrote: > > Not sure of the exact pros and cons, but we were following certain rules > like , if it's business logic which needs to be implemented in Database, > then it should not be done using triggers but rather should be done through > database procedure/fu

Re: Trigger usecase

2024-07-30 Thread Adrian Klaver
On 7/30/24 11:46, sud wrote: On Tue, Jul 30, 2024 at 10:54 PM Laurenz Albe > wrote: It is largely a matter of taste. The advantage of a trigger is that it works even if somebody bypasses the application to insert data. I think that trigge

Re: Trigger usecase

2024-07-30 Thread sud
On Tue, Jul 30, 2024 at 10:54 PM Laurenz Albe wrote: > > It is largely a matter of taste. > > The advantage of a trigger is that it works even if somebody bypasses the > application > to insert data. > > I think that triggers are easy to debug, but again, that's a matter of > taste. > > > Thank y

Re: Trigger usecase

2024-07-30 Thread Laurenz Albe
On Tue, 2024-07-30 at 20:46 +0530, sud wrote: > Now while loading transactions data we also get some reference data > information from > source (for example customer information) and for these , we dont want to > modify or > override the existing customer data but want to keep the old data with a

Re: Trigger usecase

2024-07-30 Thread David G. Johnston
On Tue, Jul 30, 2024 at 8:16 AM sud wrote: > > I understand, technically its possible bith the way, but want to > understand experts opinion on this and pros ans cons? > > Have client code call a function that performs the relevant work directly instead of having a trigger perform similar work.

Re: Trigger to Count Number of Logical Replication Table Changes.

2023-11-17 Thread Juan Rodrigo Alejandro Burgos Mella
Hi The only thing that can be established is that if the record does not exist, the trigger will not be updating anything in the table "tst.time_audit_tbl" for the condition "table_name = CONCAT(TG_TABLE_SCHEMA, '.', TG_TABLE_NAME)" Maybe, checking before the UPDATE, if the record does not exist,

Re: Trigger functions and parallelism

2023-10-02 Thread Karl O. Pinc
On Mon, 02 Oct 2023 13:07:19 -0400 Tom Lane wrote: > "Karl O. Pinc" writes: > > What I'm looking for is some general statements about > > parallel safety for trigger functions. I don't know > > enough about parallelism to even know if it applies > > to data modification statements. > > It do

Re: Trigger functions and parallelism

2023-10-02 Thread Tom Lane
"Karl O. Pinc" writes: > What I'm looking for is some general statements about > parallel safety for trigger functions. I don't know > enough about parallelism to even know if it applies > to data modification statements. It doesn't, which is why the docs are silent on the point.

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

Re: Trigger questions

2023-05-04 Thread David G. Johnston
On Thu, May 4, 2023 at 7:04 AM Justin wrote: > > > On Thu, May 4, 2023 at 9:49 AM DAVID ROTH wrote: > >> 1) Can I create a trigger on a view? >> 2) Do triggers cascade? >> >> Say I have an insert trigger on a table. >> And, I have an insert trigger on a view that references this table >> If I do

Re: Trigger questions

2023-05-04 Thread Adrian Klaver
On 5/4/23 07:03, Justin wrote: On Thu, May 4, 2023 at 9:49 AM DAVID ROTH > wrote: __ 1) Can I create a trigger on a view? 2) Do triggers cascade? Say I have an insert trigger on a table. And, I have an insert trigger on a view that references

Re: Trigger questions

2023-05-04 Thread Justin
On Thu, May 4, 2023 at 9:49 AM DAVID ROTH wrote: > 1) Can I create a trigger on a view? > 2) Do triggers cascade? > > Say I have an insert trigger on a table. > And, I have an insert trigger on a view that references this table > If I do an insert on the view, will both triggers fire? > Can not

Re: Trigger functions and FDW tables

2022-04-04 Thread Michael Nolan
Thanks for confirming my suspicions, I'm working on a plan B to deal with this as best I can. -- Mike Nolan On Mon, Apr 4, 2022 at 9:23 AM Laurenz Albe wrote: > On Mon, 2022-04-04 at 09:18 -0500, Michael Nolan wrote: > > Is it not recommended to use a FDW table in a trigger function? > > Yes, I

Re: Trigger functions and FDW tables

2022-04-04 Thread Laurenz Albe
On Mon, 2022-04-04 at 09:18 -0500, Michael Nolan wrote: > Is it not recommended to use a FDW table in a trigger function? Yes, I would say that is not recommended. While a lag of a few seconds, like you describe, should not be the normal case (you should investigate that), it is hard to exclude i

Re: trigger impacting insertion of records

2021-05-10 Thread Michael Lewis
It seems like there is some flaw here. From my reading, on insert of any row, you are updating ALL rows in the same table to just remove an underscore if it matches the pattern of 'US_' at the beginning. That doesn't seem likely to be what you want. I'd think you would want something like the below

Re: trigger impacting insertion of records

2021-05-07 Thread Adrian Klaver
On 5/6/21 11:37 PM, Atul Kumar wrote: hi, The data is inserting using some json sript which is working fine in our stating server and inserting complete records. But in production data insertion is slow and after some insertion it just abort somehow. DB logs are given below: #PostGreSQL: idl

Re: trigger impacting insertion of records

2021-05-06 Thread Atul Kumar
hi, The data is inserting using some json sript which is working fine in our stating server and inserting complete records. But in production data insertion is slow and after some insertion it just abort somehow. DB logs are given below: #PostGreSQL: idle^^2021-05-06 18:06:09 PDT^^bonzipay^^us

Re: trigger impacting insertion of records

2021-05-06 Thread Adrian Klaver
On 5/6/21 12:45 AM, Atul Kumar wrote: Hi, I have simple table having structure like given below: \d bp_ach_trans Table "bonzipay.bp_ach_trans" Column | Type | Modifiers ++

Re: trigger impacting insertion of records

2021-05-06 Thread Vijaykumar Jain
just simplified, but it works fine for me. create table example(id int primary key, value text); create or replace function trg_fn() returns trigger language plpgsql as $$ begin RAISE NOTICE 'trigger_func(%) called: action = %, when = %, level = %', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL;

Re: Trigger with conditional predicates

2021-01-04 Thread Alban Hertroys
> On 4 Jan 2021, at 20:02, Dirk Mika wrote: > >>> On 1 Jan 2021, at 16:56, Dirk Mika wrote: >>> >>> Hi all and a happy new Year! >>> >>> We have an Oracle schema that is to be converted to PostgreSQL, where >>> conditional predicates are used in some triggers. >>> >>> In particular, column

Re: Trigger with conditional predicates

2021-01-04 Thread Christophe Pettus
> On Jan 4, 2021, at 11:06, Dirk Mika wrote: > > See thread below: > > https://www.postgresql.org/message-id/VisenaEmail.26.7cbf2947c8d23ceb.1769a2755ff%40tc7-visena > > I found that thread already, but It doesn't not provide a solution to my > problem. One possibility, which is admittedly

Re: Trigger with conditional predicates

2021-01-04 Thread Dirk Mika
>>> In particular, columns are populated with values if they are not specified >>> in the update statement which is used. >>> Usually with an expression like this: >>> >>> IF NOT UPDATING('IS_CANCELED') >>> THEN >>> :new.is_canceled := ...; >>> END IF; >>> >>> I have not

Re: Trigger with conditional predicates

2021-01-04 Thread Dirk Mika
-- Dirk Mika Software Developer mika:timing GmbH Strundepark - Kürtener Str. 11b 51465 Bergisch Gladbach Germany fon +49 2202 2401-1197 dirk.m...@mikatiming.de www.mikatiming.de AG Köln HRB 47509 * WEEE-Reg.-Nr. DE 90029884 Geschäftsführer: Harald Mika, Jörg Mika > > On 1 Jan 2021, at 16:56,

Re: Trigger with conditional predicates

2021-01-02 Thread Adrian Klaver
On 1/2/21 2:23 AM, Dirk Mika wrote: In particular, columns are populated with values if they are not specified in the update statement which is used. Usually with an expression like this: IF NOT UPDATING('IS_CANCELED') THEN :new.is_canceled := ...; END IF; I have not

Re: Trigger with conditional predicates

2021-01-02 Thread Alban Hertroys
> On 1 Jan 2021, at 16:56, Dirk Mika wrote: > > Hi all and a happy new Year! > > We have an Oracle schema that is to be converted to PostgreSQL, where > conditional predicates are used in some triggers. > > In particular, columns are populated with values if they are not specified in > the

Re: Trigger with conditional predicates

2021-01-02 Thread Dirk Mika
> > In particular, columns are populated with values if they are not specified > > in the update statement which is used. > > Usually with an expression like this: > > > > IF NOT UPDATING('IS_CANCELED') > > THEN > > :new.is_canceled := ...; > > END IF; > > > > I have not fou

Re: Trigger with conditional predicates

2021-01-02 Thread Dirk Mika
> > PostgreSQL doesn't have an exact equivalent. Typically, the OLD and NEW > > values are compared and then action is taken based on that. For example, > > in PL/pgSQL: > > IF NEW.is_canceled IS NOT DISTINCT FROM OLD.is_canceled THEN > > NEW.is_canceled := etc etc ; > > ENDIF; > > There's cur

Re: Trigger with conditional predicates

2021-01-01 Thread Tom Lane
Christophe Pettus writes: > PostgreSQL doesn't have an exact equivalent. Typically, the OLD and NEW > values are compared and then action is taken based on that. For example, in > PL/pgSQL: > IF NEW.is_canceled IS NOT DISTINCT FROM OLD.is_canceled THEN > NEW.is_canceled := etc etc ; > EN

Re: Trigger with conditional predicates

2021-01-01 Thread Christophe Pettus
> On Jan 1, 2021, at 07:56, Dirk Mika wrote: > In particular, columns are populated with values if they are not specified in > the update statement which is used. > Usually with an expression like this: > > IF NOT UPDATING('IS_CANCELED') > THEN > :new.is_canceled := ...; >

Re: Trigger transaction isolation

2020-09-02 Thread Dirk Lattermann
Thank you, Tom, for this valuable information. On Tue, 01 Sep 2020 11:02:01 -0400 1Tom Lane wrote: > visibility rules are the same as for any other function. So the > answer to the OP's question depends on the transaction's isolation > level and (for typical PLs) on whether the function is VOLA

Re: Trigger transaction isolation

2020-09-01 Thread Tom Lane
Adrian Klaver writes: > As I understand it a trigger function runs in its own transaction so the > rules from below apply: > https://www.postgresql.org/docs/12/transaction-iso.html No, a trigger is part of the calling transaction. There's nothing special about it other than the condition causin

Re: Trigger transaction isolation

2020-09-01 Thread Adrian Klaver
On 9/1/20 7:07 AM, Dirk Lattermann wrote: Hello! Since unfortunately nobody has yet replied to my question, I'd like to know if this is the right list to ask this question on or if I should try another mailing list. Maybe the answer is too obvious, but in that case I'd appreciate a short hint to

Re: Trigger transaction isolation

2020-09-01 Thread Dirk Lattermann
Hello! Since unfortunately nobody has yet replied to my question, I'd like to know if this is the right list to ask this question on or if I should try another mailing list. Maybe the answer is too obvious, but in that case I'd appreciate a short hint to help me finding it. Maybe it's a hard quest

Re: Trigger not firing

2020-06-01 Thread Adrian Klaver
On 6/1/20 3:09 AM, Hans wrote: I've had a weird problem in a production system. The customer had installed a new server with our software on it. The software installs a Postgres database schema that includes a number of triggers. The triggers perform inserts into an additional table. How is t

Re: Trigger not firing

2020-06-01 Thread Hans
you trigger can be much faster if you replace FOREACH cycle by unnest INSERT INTO generic.usergroup_test(test_id, usergroup_id) VALUES(NEW.id, UNNEST(NEW.usergroup_ids)); Thanks! Appreciated :-) Hans

Re: Trigger not firing

2020-06-01 Thread Pavel Stehule
po 1. 6. 2020 v 12:09 odesílatel Hans napsal: > >> I've had a weird problem in a production system. The customer had > >> installed a new server with our software on it. The software installs > >> a Postgres database schema that includes a number of triggers. The > >> triggers perform inserts int

Re: Trigger not firing

2020-06-01 Thread Hans
I've had a weird problem in a production system. The customer had installed a new server with our software on it. The software installs a Postgres database schema that includes a number of triggers. The triggers perform inserts into an additional table. How is the install done? Our instructi

Re: Trigger not firing

2020-05-31 Thread Adrian Klaver
On 5/31/20 6:19 AM, Hans wrote: Hi, I've had a weird problem in a production system. The customer had installed a new server with our software on it. The software installs a Postgres database schema that includes a number of triggers. The triggers perform inserts into an additional table.

Re: Trigger

2020-02-25 Thread Adrian Klaver
On 2/25/20 9:08 AM, Alban Hertroys wrote: On 25 Feb 2020, at 17:53, Adrian Klaver wrote: On 2/25/20 12:01 AM, Sonam Sharma wrote: I have a trigger, like many other triggers that fire after update and checks a field of the OLD set. For some reason this trigger throw this error: ERROR: record

Re: Trigger

2020-02-25 Thread Alban Hertroys
> On 25 Feb 2020, at 17:53, Adrian Klaver wrote: > > On 2/25/20 12:01 AM, Sonam Sharma wrote: >> I have a trigger, like many other triggers that fire after >> update and checks a field of the OLD set. For some reason this trigger throw >> this error: >> ERROR: record "old" has no field "ivo_st

Re: Trigger

2020-02-25 Thread Adrian Klaver
On 2/25/20 12:01 AM, Sonam Sharma wrote: I have a trigger, like many other triggers that fire after update and checks a field of the OLD set. For some reason this trigger throw this error: ERROR: record "old" has no field "ivo_sts_cd" CONTEXT: SQL statement if exc_count = 0 then UPDATE pp

Re: Trigger

2020-02-25 Thread Adrian Klaver
On 2/25/20 12:01 AM, Sonam Sharma wrote: I have a trigger, like many other triggers that fire after update and checks a field of the OLD set. For some reason this trigger throw this error: ERROR: record "old" has no field "ivo_sts_cd" CONTEXT: SQL statement "UPDATE dbo.T8071_CAI_IVO_HDR SET

Re: Trigger

2019-10-11 Thread Charles Clavadetscher
Hello On 2019-10-11 12:59, Sonam Sharma wrote: Can someone please help me in how to list all the triggers with their respective tables and the trigger body You can use the catalogs: SELECT t.tgname, t.tgrelid::regclass, t.tgfoid::regprocedure as function_name, pg_get_functiondef(t.tgfoid) as

Re: Trigger function does not modify the NEW value

2019-06-28 Thread Igal @ Lucee.org
On 6/28/2019 8:07 PM, David Rowley wrote: On Sat, 29 Jun 2019 at 14:54, Igal @ Lucee.org wrote: create trigger tr_on_table_modified after insert or delete or update on some_table for each row execute procedure on_table_modified(); I can see in the output the notices with the expec

Re: Trigger function does not modify the NEW value

2019-06-28 Thread David Rowley
On Sat, 29 Jun 2019 at 14:54, Igal @ Lucee.org wrote: > create trigger tr_on_table_modified after insert or delete or update > on some_table for each row execute procedure on_table_modified(); > I can see in the output the notices with the expected values, but the value > in the upda

Re: Trigger bug ?

2019-05-22 Thread PegoraroF10
ok, you won. Sorry, I didn´t read that "If neither is specified, FOR EACH STATEMENT is the default" -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html

Re: Trigger bug ?

2019-05-22 Thread David G. Johnston
On Wed, May 22, 2019 at 3:41 PM PegoraroF10 wrote: > I´m not saying it should inspect function code, but I think it should deny > when I try to create a trigger missing a needed argument. > Guessing you missed my earlier response... > When I do ... > create table MyTable(integer); > gives me a

Re: Trigger bug ?

2019-05-22 Thread Adrian Klaver
On 5/22/19 3:21 PM, PegoraroF10 wrote: sorry, I wasn´t clear, when I sad returning Null I tried to say that new.PK was Null, not the function result > Try to create exactly what I sent you and you´ll see null values on that pk. Yes because FOR EACH STATEMENT may deal with multiple rows, so it

Re: Trigger bug ?

2019-05-22 Thread PegoraroF10
I´m not saying it should inspect function code, but I think it should deny when I try to create a trigger missing a needed argument. When I do ... create table MyTable(integer); gives me an "syntax error at end of input" because I forgot field name. why when I do ... create trigger MyTrigger aft

Re: Trigger bug ?

2019-05-22 Thread David G. Johnston
On Wed, May 22, 2019 at 3:21 PM PegoraroF10 wrote: > Try to create exactly what I sent you and you´ll see null values on that > pk. > You should probably submit self-contained examples if you need the user to do this. > And that occurs just because that trigger was created without EACH > ROW/S

Re: Trigger bug ?

2019-05-22 Thread PegoraroF10
sorry, I wasn´t clear, when I sad returning Null I tried to say that new.PK was Null, not the function result. Try to create exactly what I sent you and you´ll see null values on that pk. And that occurs just because that trigger was created without EACH ROW/STATEMENT. So, my question is, PG shou

Re: Trigger bug ?

2019-05-22 Thread David G. Johnston
On Wed, May 22, 2019 at 2:33 PM PegoraroF10 wrote: > We forgot FOR EACH ROW/STATEMENT when created our trigger. > > On docs it´s written {ROW/STATEMENT} between {}, so it´s needed. But why > did > it accepted our command to create that trigger ? > You only partially absorbed the syntax doc for t

Re: Trigger bug ?

2019-05-22 Thread Adrian Klaver
On 5/22/19 2:33 PM, PegoraroF10 wrote: We created a usual trigger which seemed to be not firing or not working properly. Then we put some raise notices on it and saw that it was returning Null values. But why, it´s after insert and is a primary key, cannot be null. https://www.postgresql.org/do

Re: Trigger when user logs in

2019-04-14 Thread Michael Nolan
On Sun, Apr 14, 2019 at 4:06 AM Peter J. Holzer wrote: > > If you want to prevent a user from logging in (which is functionally > equivalent but a bit stronger than "instantly kick off"), then this is > definitely something that could and should be implemented via PAM (I'm > not sure what informa

Re: Trigger when user logs in

2019-04-14 Thread Ron
On 4/14/19 4:05 AM, Peter J. Holzer wrote: On 2019-04-13 22:22:16 -0500, Ron wrote: In our case, another looming Auditor requirement is to be able to instantly kick off -- or at least send a warning email -- when certain roles log in from unapproved IP addresses or programs.  For example, servic

Re: Trigger when user logs in

2019-04-14 Thread Peter J. Holzer
On 2019-04-13 22:22:16 -0500, Ron wrote: > In our case, another looming Auditor requirement is to be able to instantly > kick off -- or at least send a warning email -- when certain roles log in > from unapproved IP addresses or programs.  For example, service accounts > should only be able to log

Re: Trigger when user logs in

2019-04-13 Thread Ron
On 4/13/19 7:28 PM, Schneider, Jeremy wrote: On Apr 11, 2019, at 19:52, Tom Lane wrote: Ron writes: I bet requests like this will start to make it onto the beaten path. Meh. I'm not that excited about inventing our own versions of wheels that already exist, especially when there's nothing v

Re: Trigger when user logs in

2019-04-13 Thread Dan Langille
Pushover.net comes to mind. The email sending should not delay login. If you want notifications, look at mqtt. https://dan.langille.org/2018/04/15/using-mtqq-to-create-a-notification-network-mosquitto-mqttwarn-hare-and-hared/ Lightweight, non-pausing solution. HTH -- Dan Langille d...@

Re: Trigger when user logs in

2019-04-13 Thread Schneider, Jeremy
> On Apr 13, 2019, at 17:28, Schneider, Jeremy wrote: > >> On Apr 11, 2019, at 19:52, Tom Lane wrote: >> >> Ron writes: >>> I bet requests like this will start to make it onto the beaten path. >> >> Meh. I'm not that excited about inventing our own versions of wheels >> that already exist,

Re: Trigger when user logs in

2019-04-13 Thread Schneider, Jeremy
> On Apr 11, 2019, at 19:52, Tom Lane wrote: > > Ron writes: >> I bet requests like this will start to make it onto the beaten path. > > Meh. I'm not that excited about inventing our own versions of wheels > that already exist, especially when there's nothing very Postgres-specific > about th

Re: Trigger when user logs in

2019-04-11 Thread Ron
On 4/11/19 9:52 PM, Tom Lane wrote: Ron writes: On 4/11/19 9:12 PM, Tom Lane wrote: PAM is the usual suggestion Can you be more specific? I'm suggesting that you use PAM auth https://www.postgresql.org/docs/current/auth-pam.html and then configure the email behavior on the PAM side. Unde

Re: Trigger when user logs in

2019-04-11 Thread Tom Lane
Ron writes: > On 4/11/19 9:12 PM, Tom Lane wrote: >> PAM is the usual suggestion > Can you be more specific? I'm suggesting that you use PAM auth https://www.postgresql.org/docs/current/auth-pam.html and then configure the email behavior on the PAM side. The PAM doc link we provided there lea

Re: Trigger when user logs in

2019-04-11 Thread Ron
On 4/11/19 9:12 PM, Tom Lane wrote: Ron writes: PCI auditors have mandated that our databases (all running v9.6) send an email when certain users log in.  Thus, I've been searching for how to do this, but without much luck. PAM is the usual suggestion Can you be more specific?  (All users ex

Re: Trigger when user logs in

2019-04-11 Thread Tom Lane
Ron writes: > PCI auditors have mandated that our databases (all running v9.6) send an > email when certain users log in.  Thus, I've been searching for how to do > this, but without much luck. PAM is the usual suggestion when you need off-the-beaten-path login behavior.

Re: Trigger function always logs postgres as user name

2019-02-15 Thread Alexander Reichstadt
HI, The answer to the question is that you need to use session_user instead of user or current_user. Cheers, Alex > On 9 Feb 2019, at 10:08, Alexander Reichstadt wrote: > > Hi, > > I setup trigger functions for logging, and while they do work and get > triggered, the current_user always in

Re: Trigger function always logs postgres as user name

2019-02-09 Thread Francisco Olarte
Alexander: On Sat, Feb 9, 2019 at 1:32 PM Alexander Reichstadt wrote: > I setup trigger functions for logging, and while they do work and get > triggered, the current_user always insert “postgres” even when > updates/deletes/inserts are caused by users of another name. > How do I get it to use

Re: Trigger to create string to inverse SQL statement

2018-03-08 Thread Francisco Olarte
Jacek: On Thu, Mar 8, 2018 at 1:53 PM, Łukasz Jarych wrote: > maybe somebody wrote SP to invert update statement? Maybe, but if you are going to ask for it you better define the problem a little. Francisco Olarte.

Re: Trigger to create string to inverse SQL statement

2018-03-08 Thread Francisco Olarte
Hello: On Thu, Mar 8, 2018 at 1:51 PM, Łukasz Jarych wrote: > what do you mean use external program to build inverted queries. Do you have > any examples? Please, do not top quote, or the thread will get difficult to follow fast. That being said. Capturing a DML in a trigger is relatively easy

Re: Trigger to create string to inverse SQL statement

2018-03-08 Thread Łukasz Jarych
maybe somebody wrote SP to invert update statement? Best, Jacek 2018-03-08 13:51 GMT+01:00 Łukasz Jarych : > thank you, > > what do you mean use external program to build inverted queries. Do you > have any examples? > > Best, > Jacek > > 2018-03-08 13:44 GMT+01:00 Francisco Olarte : > >> Hello:

Re: Trigger to create string to inverse SQL statement

2018-03-08 Thread Łukasz Jarych
thank you, what do you mean use external program to build inverted queries. Do you have any examples? Best, Jacek 2018-03-08 13:44 GMT+01:00 Francisco Olarte : > Hello: > > On Thu, Mar 8, 2018 at 1:32 PM, Łukasz Jarych wrote: > >> >> >> i have a trigger which is added log history: >> >> >> >>

Re: Trigger to create string to inverse SQL statement

2018-03-08 Thread Francisco Olarte
Hello: On Thu, Mar 8, 2018 at 1:32 PM, Łukasz Jarych wrote: > > > i have a trigger which is added log history: > > > > ​I'll trust it is, but I cannot really see any thing in there, it may be better if in the future you used something like psql and pasted the data in a text format, which people

Re: Trigger (or something similar) on table rename?

2018-02-16 Thread Tom Lane
Ken Tanzer writes: > Presumably the complete command would let you figure out it's a rename, and > the old and new tables. But I found this message ( > https://postgrespro.com/list/thread-id/1561932) stating that a > pg_ddl_command could only be processed in C, not in a procedural language. > I'm

Re: Trigger (or something similar) on table rename?

2018-02-16 Thread Ken Tanzer
On Thu, Feb 15, 2018 at 11:01 AM, Tom Lane wrote: > Ken Tanzer writes: > > Something like a trigger on the table rename would be ideal for my > > purposes. Anything like that possible? Thanks! > > Recent PG versions have "event triggers" which would serve the purpose. > However, the infrastruc

Re: Trigger (or something similar) on table rename?

2018-02-15 Thread Paul Jungwirth
On 02/15/2018 10:52 AM, Ken Tanzer wrote: Hi.  I'm wondering about possibilities for taking action when a table is renamed. I've looked into this a bit. Here is what I understand: Since 9.3 Postgres has had "event triggers" which can run code on DDL events (https://www.postgresql.org/docs/cu

Re: Trigger (or something similar) on table rename?

2018-02-15 Thread Tom Lane
Ken Tanzer writes: > Something like a trigger on the table rename would be ideal for my > purposes. Anything like that possible? Thanks! Recent PG versions have "event triggers" which would serve the purpose. However, the infrastructure for them isn't very fully built out yet. I'm not sure if y

Re: Trigger (or something similar) on table rename?

2018-02-15 Thread Adrian Klaver
On 02/15/2018 10:52 AM, Ken Tanzer wrote: Hi.  I'm wondering about possibilities for taking action when a table is renamed. Specifically in this case, I'm using table_log, which when you use it on a table creates a new table, sequence and index that is tied to the table name.  Of course, if t