agora inbox for pljava-dev@postgresql.org  
help / color / mirror / Atom feed
[Pljava-dev] Obtaining Query from Trigger
6+ messages / 0 participants
[nested] [flat]

* [Pljava-dev] Obtaining Query from Trigger
@ 2005-06-07 22:08  
  0 siblings, 2 replies; 6+ messages in thread

From:  @ 2005-06-07 22:08 UTC (permalink / raw)

  Hi!
  
  I started using pljava two days ago, so I apologize if this was
already posted before.

  I need to get the sql query that fired a trigger on a DB so that it
can be re-issued to another DB.

  For example, if 'select * from users' fired a before select trigger,
the string with the query should be somehow passed to the java
function that is associated to that trigger.

  Any ideas??

  Joao Afonso.




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

* [Pljava-dev] Obtaining Query from Trigger
@ 2005-06-08 06:23  
  parent: 
  1 sibling, 0 replies; 6+ messages in thread

From:  @ 2005-06-08 06:23 UTC (permalink / raw)

Joao Afonso wrote:

>  Hi!
>  
>  I started using pljava two days ago, so I apologize if this was
>already posted before.
>
>  I need to get the sql query that fired a trigger on a DB so that it
>can be re-issued to another DB.
>
>  For example, if 'select * from users' fired a before select trigger,
>the string with the query should be somehow passed to the java
>function that is associated to that trigger.
>  
>
I hate to dissapoint you but to my knowledge a trigger is never fired 
for SELECT. Only INSERT, UPDATE, and DELETE will fire triggers.

Regards,
Thomas Hallgren






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

* [Pljava-dev] Obtaining Query from Trigger
@ 2005-06-08 14:20  
  parent: 
  1 sibling, 2 replies; 6+ messages in thread

From:  @ 2005-06-08 14:20 UTC (permalink / raw)

  Ok, my mistake... I'll need to think of something else. But I still
need to get the query that fired on an insert, update or delete. Could
you help me with that??

  Thanks in advance.


On 6/8/05, Thomas Hallgren <thhal at mailblocks.com> wrote:
> Joao Afonso wrote:
> 
> >  Hi!
> >
> >  I started using pljava two days ago, so I apologize if this was
> >already posted before.
> >
> >  I need to get the sql query that fired a trigger on a DB so that it
> >can be re-issued to another DB.
> >
> >  For example, if 'select * from users' fired a before select trigger,
> >the string with the query should be somehow passed to the java
> >function that is associated to that trigger.
> >
> >
> I hate to dissapoint you but to my knowledge a trigger is never fired
> for SELECT. Only INSERT, UPDATE, and DELETE will fire triggers.
> 
> Regards,
> Thomas Hallgren
> 
> 
>




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

* [Pljava-dev] Obtaining Query from Trigger
@ 2005-06-08 14:41  
  parent: 
  1 sibling, 0 replies; 6+ messages in thread

From:  @ 2005-06-08 14:41 UTC (permalink / raw)

Joao Afonso wrote:

>  Ok, my mistake... I'll need to think of something else. But I still
>need to get the query that fired on an insert, update or delete. Could
>you help me with that??
>
>  Thanks in advance.
>  
>
I'm sorry but no, that's not planned. I can't really see the use-case 
where it would be really useful and it implies a fairly advanced 
mechanism. Consider the following:

INSERT INTO foo(a,b) SELECT a,b FROM bar;

in combination with a "BEFORE INSERT ON EACH ROW" trigger on table foo. 
What statement would you expect to see? Same thing is of course true for 
updates and deletes that deals with several rows.

Perhaps I'd be able to help if you elaborate a bit on what you want to 
use this for.

Regards,
Thomas Hallgren






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

* [Pljava-dev] Obtaining Query from Trigger
@ 2005-06-08 15:05  
  parent: 
  1 sibling, 1 reply; 6+ messages in thread

From:  @ 2005-06-08 15:05 UTC (permalink / raw)

  If I have the following:

   - insert into user ("user_id", "name") values ('1','test')

 I want to pass the above string as a parameter to a Java function,
because I might have to modify it and even pass the query to a
different DB.

  In the case that this can not be done at all, I guess I could obtain
the data that was inserted to the DB with a SELECT and then pass it to
a java function?

  I'm sorry if I'm being a little vague on the subject, but like I
said I'm new to pljava and these are just some ideas I need to test
for a project I'm developing.

On 6/8/05, Thomas Hallgren <thhal at mailblocks.com> wrote:
> Joao Afonso wrote:
> 
> >  Ok, my mistake... I'll need to think of something else. But I still
> >need to get the query that fired on an insert, update or delete. Could
> >you help me with that??
> >
> >  Thanks in advance.
> >
> >
> I'm sorry but no, that's not planned. I can't really see the use-case
> where it would be really useful and it implies a fairly advanced
> mechanism. Consider the following:
> 
> INSERT INTO foo(a,b) SELECT a,b FROM bar;
> 
> in combination with a "BEFORE INSERT ON EACH ROW" trigger on table foo.
> What statement would you expect to see? Same thing is of course true for
> updates and deletes that deals with several rows.
> 
> Perhaps I'd be able to help if you elaborate a bit on what you want to
> use this for.
> 
> Regards,
> Thomas Hallgren
> 
> 
>




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

* [Pljava-dev] Obtaining Query from Trigger
@ 2005-06-08 15:12  
  parent: 
  0 siblings, 0 replies; 6+ messages in thread

From:  @ 2005-06-08 15:12 UTC (permalink / raw)

Joao Afonso wrote:

>  If I have the following:
>
>   - insert into user ("user_id", "name") values ('1','test')
>
> I want to pass the above string as a parameter to a Java function,
>because I might have to modify it and even pass the query to a
>different DB.
>
>  In the case that this can not be done at all, I guess I could obtain
>the data that was inserted to the DB with a SELECT and then pass it to
>a java function?
>
>  I'm sorry if I'm being a little vague on the subject, but like I
>said I'm new to pljava and these are just some ideas I need to test
>for a project I'm developing.
>  
>
If you want to know the name of the table and the data that will be 
inserted, then use the TriggerData instance that is passed to the 
trigger.  You'll find methods to obtain the relation name (i.e. the 
table name) and the new tuple. That will be far more efficient then 
parsing SQL statements.

Regards,
Thomas Hallgren






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


end of thread, other threads:[~2005-06-08 15:12 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-06-07 22:08 [Pljava-dev] Obtaining Query from Trigger 
2005-06-08 06:23 ` 
2005-06-08 14:20 ` 
2005-06-08 14:41   ` 
2005-06-08 15:05   ` 
2005-06-08 15:12     ` 

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox