Обсуждение: Latest transcation
Hi All,
Is there any way to know programatically which is the latest insert/update occured to a particular table?
What are the values which are inserted/updated to that table?
Help appreciated.
Thx.,
Anagha
On Thu, Jun 19, 2003 at 10:46:22 +0530, Anagha Joshi <ajoshi@nulinkinc.com> wrote: > Hi All, > Is there any way to know programatically which is the latest > insert/update occured to a particular table? > What are the values which are inserted/updated to that table? That depends on what you really are trying to do. It sounds like using a sequnce, nextval and currval might work. That could be used to track the latest change in one session. If you try to look at the latest change to a table accross all sessions, things get a bit murky. A more precise description of what you are trying to do might result in some other suggestions.
Consider this: Transcation begin ' ' Insert on table x ' ' Trascation end; My client C++ front end is multi-threaded. The above 'transcation' block is in thread -y . I want to know the info. abt' last row inserted into table in this transcation block. Info contains the details like time of insertion of a row and data in that row. I think this sufficely explains what I want. -Anagha -----Original Message----- From: Bruno Wolff III [mailto:bruno@wolff.to] Sent: Thursday, June 19, 2003 4:00 PM To: Anagha Joshi Cc: pgsql-admin@postgresql.org Subject: Re: [ADMIN] Latest transcation On Thu, Jun 19, 2003 at 10:46:22 +0530, Anagha Joshi <ajoshi@nulinkinc.com> wrote: > Hi All, > Is there any way to know programatically which is the latest > insert/update occured to a particular table? What are the values which > are inserted/updated to that table? That depends on what you really are trying to do. It sounds like using a sequnce, nextval and currval might work. That could be used to track the latest change in one session. If you try to look at the latest change to a table accross all sessions, things get a bit murky. A more precise description of what you are trying to do might result in some other suggestions.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wednesday 18 June 2003 22:16, Anagha Joshi wrote: > Is there any way to know programatically which is the latest > insert/update occured to a particular table? > What are the values which are inserted/updated to that table? > If you want to record transaction history on a table, you'll need to use triggers and a separate table to store the history in. When the transaction that modified the table commits, the modification to the history table from the trigger will commit also, in the order they committed. - -- Jonathan Gardner <jgardner@jonathangardner.net> (was jgardn@alumni.washington.edu) Live Free, Use Linux! -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+8cD2WgwF3QvpWNwRAnoAAJ4j/gaXd2V748O2M/8pNvY9IYhGkgCeNhe2 KjXh8NwRMtMtfYFvPX69wWE= =8Aa3 -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday 19 June 2003 04:41, Anagha Joshi wrote: > My client C++ front end is multi-threaded. The above 'transcation' block > is in thread -y . > I want to know the info. abt' last row inserted into table in this > transcation block. > Info contains the details like time of insertion of a row and data in > that row. > > I think this sufficely explains what I want. > There are some things you can do at the application level to record what was done in a seperate thread or even process. With threads, you can use shared variables and semaphores. With processes, you can use some form of IPC or shared memory. If you decide to go at an application layer, it is beyond the scope of the ADMIN list, and better suited for a discussion with your peers in that language and environment. If you go for a server-side solution (because the application doesn't know what was last inserted and when), then you'll want to use triggers as I described in a previous posting. - -- Jonathan Gardner <jgardner@jonathangardner.net> (was jgardn@alumni.washington.edu) Live Free, Use Linux! -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+8cOoWgwF3QvpWNwRAmGkAJ4pE8Eb9V/kiyBFqLCqr/2nNqA3HwCg0PE2 2TCK7YF50MKLwbUurS1aqlY= =hvKY -----END PGP SIGNATURE-----
Yes...I'm aware of that and have tried also by maintaining extra table. But how to to the following: 1. If insertion takes place, I want to return to the client the values (with field names of course) which are inserted into the tables. In each case table might be different. 2. If modification takes places, I want to know the values which are modified with field names and return them to the client. More precisely, My C++ client -- ' ' " Transcation begin insert/update query to the backend is fired. //control is tranferred to the trigger //After trigger procedure is executed, I want at this point the values inserted/modified so //as to pass them back Transcation end ' ' Pls. help Anagha -----Original Message----- From: Jonathan Gardner [mailto:jgardner@jonathangardner.net] Sent: Thursday, June 19, 2003 7:26 PM To: Anagha Joshi; pgsql-admin@postgresql.org Subject: Re: [ADMIN] Latest transcation -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wednesday 18 June 2003 22:16, Anagha Joshi wrote: > Is there any way to know programatically which is the latest > insert/update occured to a particular table? What are the values which > are inserted/updated to that table? > If you want to record transaction history on a table, you'll need to use triggers and a separate table to store the history in. When the transaction that modified the table commits, the modification to the history table from the trigger will commit also, in the order they committed. - -- Jonathan Gardner <jgardner@jonathangardner.net> (was jgardn@alumni.washington.edu) Live Free, Use Linux! -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+8cD2WgwF3QvpWNwRAnoAAJ4j/gaXd2V748O2M/8pNvY9IYhGkgCeNhe2 KjXh8NwRMtMtfYFvPX69wWE= =8Aa3 -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Friday 20 June 2003 01:27, Anagha Joshi wrote: > Yes...I'm aware of that and have tried also by maintaining extra table. > But how to to the following: > 1. If insertion takes place, I want to return to the client the > values (with field names of course) which are inserted into the > tables. In each case table might be different. > When you insert a single row, PostgreSQL returns the OID of that row. Just follow up with a select (SELECT * FROM <your table> WHERE OID=<the oid>) and you'll get all the info you need. > 2. If modification takes places, I want to know the values which > are modified with field names and return them to the client. > You can do that by checking what is different between the data you inserted and the data you get from the select statement. > More precisely, > My C++ client -- > ' > ' > " > Transcation begin > insert/update query to the backend is fired. > //control is tranferred to the trigger > //After trigger procedure is executed, I want at this > point the values inserted/modified so //as to pass them back > Transcation end > ' > ' > I don't think it can work the way you would like it. Try this algorithm. For insert: 1. Insert query is run. (Trigger, other table inserts/updates performed) 2. With the OID from the insert, select the data. For Update: 1. Update query is run. (Triggers, etc, are run as well). 2. With the OID (or Primary Key), select the data you just updated. You can turn these two procedures into a stored procedure pretty easily. This way, all you do is call a stored procedure, and it will pass back all the data you need. You get a free transaction block inside the stored procedure as well. - -- Jonathan Gardner <jgardner@jonathangardner.net> (was jgardn@alumni.washington.edu) Live Free, Use Linux! -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+8w95WgwF3QvpWNwRAsVgAKCu48FN0VkRvXc9a2d9Qc91YU6jaQCdG4h4 kH42h4oWrsh1f1Splm0KNkA= =zOMj -----END PGP SIGNATURE-----