pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Parameter passing in trigger function write in C
7+ messages / 3 participants
[nested] [flat]

* Parameter passing in trigger function write in C
@ 2018-04-27 01:13 a <372660931@qq.com>
  2018-04-27 01:36 ` Re: Parameter passing in trigger function write in C Adrian Klaver <adrian.klaver@aklaver.com>
  2018-04-27 06:20 ` Re: Parameter passing in trigger function write in C Laurenz Albe <laurenz.albe@cybertec.at>
  0 siblings, 2 replies; 7+ messages in thread

From: a @ 2018-04-27 01:13 UTC (permalink / raw)
  To: pgsql-general

Hey everyone:


I was request to write a trigger that perform the following function:


1, The trigger will be set to exam all statement that will result change of datas


2, The trigger will exam three information other than the data updated or inserted: user name, password and reasons of change


3, It will record down, in some format, the time and content of the change.


Therefore, I would need some way of passing parameters into the trigger function. Can anyone give me some instructions on how to do it or, if it is possible??

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Parameter passing in trigger function write in C
  2018-04-27 01:13 Parameter passing in trigger function write in C a <372660931@qq.com>
@ 2018-04-27 01:36 ` Adrian Klaver <adrian.klaver@aklaver.com>
  2018-04-27 01:48   ` Re: Parameter passing in trigger function write in C a <372660931@qq.com>
  1 sibling, 1 reply; 7+ messages in thread

From: Adrian Klaver @ 2018-04-27 01:36 UTC (permalink / raw)
  To: a <372660931@qq.com>; pgsql-general

On 04/26/2018 06:13 PM, a wrote:
> Hey everyone:
> 
> I was request to write a trigger that perform the following function:
> 
> 1, The trigger will be set to exam all statement that will result change 
> of datas
> 
> 2, The trigger will exam three information other than the data updated 
> or inserted: user name, password and reasons of change
> 
> 3, It will record down, in some format, the time and content of the change.
> 
> Therefore, I would need some way of passing parameters into the trigger 
> function. Can anyone give me some instructions on how to do it or, if it 
> is possible??

https://www.postgresql.org/docs/10/static/trigger-interface.html


-- 
Adrian Klaver
adrian.klaver@aklaver.com




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Parameter passing in trigger function write in C
  2018-04-27 01:13 Parameter passing in trigger function write in C a <372660931@qq.com>
  2018-04-27 01:36 ` Re: Parameter passing in trigger function write in C Adrian Klaver <adrian.klaver@aklaver.com>
@ 2018-04-27 01:48   ` a <372660931@qq.com>
  2018-04-27 14:16     ` Re: Parameter passing in trigger function write in C Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 1 reply; 7+ messages in thread

From: a @ 2018-04-27 01:48 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general

hey thanks mate, I have red that. But the actual data retirement seems to be combination of that and the SPI_get* functions. I'm still testing on it. By the way, if I can pass parameters that is out of the scope of sql statement??




------------------ Original ------------------
From: "Adrian Klaver"; 
Date: Friday, Apr 27, 2018 9:36 AM
To: "a"<372660931@qq.com>; "pgsql-general"; 
Subject: Re: Parameter passing in trigger function write in C



On 04/26/2018 06:13 PM, a wrote:
> Hey everyone:
> 
> I was request to write a trigger that perform the following function:
> 
> 1, The trigger will be set to exam all statement that will result change 
> of datas
> 
> 2, The trigger will exam three information other than the data updated 
> or inserted: user name, password and reasons of change
> 
> 3, It will record down, in some format, the time and content of the change.
> 
> Therefore, I would need some way of passing parameters into the trigger 
> function. Can anyone give me some instructions on how to do it or, if it 
> is possible??

https://www.postgresql.org/docs/10/static/trigger-interface.html


-- 
Adrian Klaver
adrian.klaver@aklaver.com

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Parameter passing in trigger function write in C
  2018-04-27 01:13 Parameter passing in trigger function write in C a <372660931@qq.com>
  2018-04-27 01:36 ` Re: Parameter passing in trigger function write in C Adrian Klaver <adrian.klaver@aklaver.com>
  2018-04-27 01:48   ` Re: Parameter passing in trigger function write in C a <372660931@qq.com>
@ 2018-04-27 14:16     ` Adrian Klaver <adrian.klaver@aklaver.com>
  2018-04-27 14:25       ` Re: Parameter passing in trigger function write in C a <372660931@qq.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Adrian Klaver @ 2018-04-27 14:16 UTC (permalink / raw)
  To: a <372660931@qq.com>; pgsql-general

On 04/26/2018 06:48 PM, a wrote:
> hey thanks mate, I have red that. But the actual data retirement seems 
> to be combination of that and the SPI_get* functions. I'm still testing 
> on it. By the way, if I can pass parameters that is out of the scope of 
> sql statement??


Can you be more specific about what parameters you are looking to pass in?

> 
> 
> ------------------ Original ------------------
> *From:* "Adrian Klaver";
> *Date:* Friday, Apr 27, 2018 9:36 AM
> *To:* "a"<372660931@qq.com>; "pgsql-general";
> *Subject:* Re: Parameter passing in trigger function write in C
> 
> On 04/26/2018 06:13 PM, a wrote:
>  > Hey everyone:
>  >
>  > I was request to write a trigger that perform the following function:
>  >
>  > 1, The trigger will be set to exam all statement that will result change
>  > of datas
>  >
>  > 2, The trigger will exam three information other than the data updated
>  > or inserted: user name, password and reasons of change
>  >
>  > 3, It will record down, in some format, the time and content of the 
> change.
>  >
>  > Therefore, I would need some way of passing parameters into the trigger
>  > function. Can anyone give me some instructions on how to do it or, if it
>  > is possible??
> 
> https://www.postgresql.org/docs/10/static/trigger-interface.html 
> <https://www.postgresql.org/docs/10/static/trigger-interface.html;
> 
> 
> -- 
> Adrian Klaver
> adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>


-- 
Adrian Klaver
adrian.klaver@aklaver.com




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Parameter passing in trigger function write in C
  2018-04-27 01:13 Parameter passing in trigger function write in C a <372660931@qq.com>
  2018-04-27 01:36 ` Re: Parameter passing in trigger function write in C Adrian Klaver <adrian.klaver@aklaver.com>
  2018-04-27 01:48   ` Re: Parameter passing in trigger function write in C a <372660931@qq.com>
  2018-04-27 14:16     ` Re: Parameter passing in trigger function write in C Adrian Klaver <adrian.klaver@aklaver.com>
@ 2018-04-27 14:25       ` a <372660931@qq.com>
  2018-04-27 14:40         ` Re: Parameter passing in trigger function write in C Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 1 reply; 7+ messages in thread

From: a @ 2018-04-27 14:25 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general

Yep, I wanna pass the brief reason of manipulating(update, insert or delete), name and password of the manipulator (This might be done by database itself). 



------------------ Original ------------------
From: "Adrian Klaver"; 
Date: Friday, Apr 27, 2018 10:16 PM
To: "a"<372660931@qq.com>; "pgsql-general"; 
Subject: Re: Parameter passing in trigger function write in C



On 04/26/2018 06:48 PM, a wrote:
> hey thanks mate, I have red that. But the actual data retirement seems 
> to be combination of that and the SPI_get* functions. I'm still testing 
> on it. By the way, if I can pass parameters that is out of the scope of 
> sql statement??


Can you be more specific about what parameters you are looking to pass in?

> 
> 
> ------------------ Original ------------------
> *From:* "Adrian Klaver";
> *Date:* Friday, Apr 27, 2018 9:36 AM
> *To:* "a"<372660931@qq.com>; "pgsql-general";
> *Subject:* Re: Parameter passing in trigger function write in C
> 
> On 04/26/2018 06:13 PM, a wrote:
>  > Hey everyone:
>  >
>  > I was request to write a trigger that perform the following function:
>  >
>  > 1, The trigger will be set to exam all statement that will result change
>  > of datas
>  >
>  > 2, The trigger will exam three information other than the data updated
>  > or inserted: user name, password and reasons of change
>  >
>  > 3, It will record down, in some format, the time and content of the 
> change.
>  >
>  > Therefore, I would need some way of passing parameters into the trigger
>  > function. Can anyone give me some instructions on how to do it or, if it
>  > is possible??
> 
> https://www.postgresql.org/docs/10/static/trigger-interface.html 
> <https://www.postgresql.org/docs/10/static/trigger-interface.html;;
> 
> 
> -- 
> Adrian Klaver
> adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>


-- 
Adrian Klaver
adrian.klaver@aklaver.com

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Parameter passing in trigger function write in C
  2018-04-27 01:13 Parameter passing in trigger function write in C a <372660931@qq.com>
  2018-04-27 01:36 ` Re: Parameter passing in trigger function write in C Adrian Klaver <adrian.klaver@aklaver.com>
  2018-04-27 01:48   ` Re: Parameter passing in trigger function write in C a <372660931@qq.com>
  2018-04-27 14:16     ` Re: Parameter passing in trigger function write in C Adrian Klaver <adrian.klaver@aklaver.com>
  2018-04-27 14:25       ` Re: Parameter passing in trigger function write in C a <372660931@qq.com>
@ 2018-04-27 14:40         ` Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Adrian Klaver @ 2018-04-27 14:40 UTC (permalink / raw)
  To: a <372660931@qq.com>; pgsql-general

On 04/27/2018 07:25 AM, a wrote:
> Yep, I wanna pass the brief reason of manipulating(update, insert or 

https://www.postgresql.org/docs/10/static/trigger-interface.html
"
tg_event

     Describes the event for which the function is called. You can use 
the following macros to examine tg_event

...

TRIGGER_FIRED_BY_UPDATE(tg_event)

     Returns true if the trigger was fired by an UPDATE command.
"


> delete), name and password of the manipulator (This might be done by 
> database itself).

As for user:

https://www.postgresql.org/docs/10/static/functions-info.html

"current_user 	name 	user name of current execution context"

Password?:

https://www.postgresql.org/docs/10/static/view-pg-shadow.html

Though if you are using password encryption it will be encrypted.

> 
> 
> ------------------ Original ------------------
> *From:* "Adrian Klaver";
> *Date:* Friday, Apr 27, 2018 10:16 PM
> *To:* "a"<372660931@qq.com>; "pgsql-general";
> *Subject:* Re: Parameter passing in trigger function write in C
> 
> On 04/26/2018 06:48 PM, a wrote:
>  > hey thanks mate, I have red that. But the actual data retirement seems
>  > to be combination of that and the SPI_get* functions. I'm still testing
>  > on it. By the way, if I can pass parameters that is out of the scope of
>  > sql statement??
> 
> 
> Can you be more specific about what parameters you are looking to pass in?
> 
>  >
>  >
>  > ------------------ Original ------------------
>  > *From:* "Adrian Klaver";
>  > *Date:* Friday, Apr 27, 2018 9:36 AM
>  > *To:* "a"<372660931@qq.com <mailto:372660931@qq.com>>; "pgsql-general";
>  > *Subject:* Re: Parameter passing in trigger function write in C
>  >
>  > On 04/26/2018 06:13 PM, a wrote:
>  >  > Hey everyone:
>  >  >
>  >  > I was request to write a trigger that perform the following function:
>  >  >
>  >  > 1, The trigger will be set to exam all statement that will result 
> change
>  >  > of datas
>  >  >
>  >  > 2, The trigger will exam three information other than the data updated
>  >  > or inserted: user name, password and reasons of change
>  >  >
>  >  > 3, It will record down, in some format, the time and content of the
>  > change.
>  >  >
>  >  > Therefore, I would need some way of passing parameters into the 
> trigger
>  >  > function. Can anyone give me some instructions on how to do it or, 
> if it
>  >  > is possible??
>  >
>  > https://www.postgresql.org/docs/10/static/trigger-interface.html 
> <https://www.postgresql.org/docs/10/static/trigger-interface.html;
>  > <https://www.postgresql.org/docs/10/static/trigger-interface.html; 
> <https://www.postgresql.org/docs/10/static/trigger-interface.html>;;
>  >
>  >
>  > --
>  > Adrian Klaver
>  > adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com> 
> <mailto:adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>>
> 
> 
> -- 
> Adrian Klaver
> adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>


-- 
Adrian Klaver
adrian.klaver@aklaver.com




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Parameter passing in trigger function write in C
  2018-04-27 01:13 Parameter passing in trigger function write in C a <372660931@qq.com>
@ 2018-04-27 06:20 ` Laurenz Albe <laurenz.albe@cybertec.at>
  1 sibling, 0 replies; 7+ messages in thread

From: Laurenz Albe @ 2018-04-27 06:20 UTC (permalink / raw)
  To: a <372660931@qq.com>; pgsql-general

a wrote:
> I was request to write a trigger that perform the following function:
> 
> 1, The trigger will be set to exam all statement that will result change of datas
> 
> 2, The trigger will exam three information other than the data updated or inserted:
>    user name, password and reasons of change
> 
> 3, It will record down, in some format, the time and content of the change.
> 
> Therefore, I would need some way of passing parameters into the trigger function.
> Can anyone give me some instructions on how to do it or, if it is possible??

The only information you can pass to a trigger function are the old and new
values of the table row being changed and the constants you can supply to
the trigger function during CREATE TRIGGER.

Everything else will have to be drawn from the current state of the database.

One thing you can do is to define your own GUC (configuration parameter)
and set that before you run the data modifying SQL statement.  Then you can
read that information in the trigger.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com




^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2018-04-27 14:40 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-04-27 01:13 Parameter passing in trigger function write in C a <372660931@qq.com>
2018-04-27 01:36 ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-04-27 01:48   ` a <372660931@qq.com>
2018-04-27 14:16     ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-04-27 14:25       ` a <372660931@qq.com>
2018-04-27 14:40         ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-04-27 06:20 ` Laurenz Albe <laurenz.albe@cybertec.at>

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