Re: [SQL] concurrency problem

2006-06-19 Thread Andrew Sullivan
On Sat, Jun 17, 2006 at 09:23:17AM +0530, sathish kumar shanmugavelu wrote: > I fetch the consultatioin_no and add one to it, i should know this > consultation_no to save the other 10 tables. because i use this number as Don't do that. Fetch the number from a sequence first: select nextval().

Re: [SQL] concurrency problem

2006-06-18 Thread Aaron Bono
Looks good but you really shoud put your stmt.close() and conn.close() in a finally block so even if there is an error everything gets cleaned up properly.  That syntax is for Java but the principle is the same for any programming language - always make sure you clean up your connections no matter

Re: [SQL] concurrency problem

2006-06-17 Thread Ash Grove
Locks are released when the containing transaction commits. There is no explicit "release." Instead of calling "begin" and "commit" as statements, I do something more like below. As Aaron mentioned, this is JDBC, not SQL. Sorry people. try { ... conn.setAutoCommit(false); //do the insert on

Re: [SQL] concurrency problem

2006-06-17 Thread Aaron Bono
When in this situation I:1. Wait until I have enough data to do a complete commit before even bothering to save any data to the database.  I want the life of my transactions to last no more than milliseconds if possible. 2. Use a BIGSERIAL for the primary keys so the IDs are assigned automatically

Re: [SQL] concurrency problem

2006-06-16 Thread sathish kumar shanmugavelu
Dear group    Its my mistake that i did not reveal the whole scenario.   Actually  within that  begin  and  commit, i insert in 10 tables. The above said table is the key table.   I fetch the consultatioin_no and add one to it, i should know this consultation_no to save the other 10 tables. because

Re: [SQL] concurrency problem

2006-06-16 Thread Aaron Bono
I know this is a Java issue but I would recommend something more like:     Statement stmt = con.createStatement();    try {   stmt.execute("begin");   stmt.execute("lock table rcp_patient_visit_monitor");    psSave.executeUpdate(); //psSave is a prepared statement    stmt.execute("

Re: [SQL] concurrency problem

2006-06-16 Thread Ash Grove
>INSERT INTO rcp_patient_visit_monitor ( >entry_no, patient_id, visit_date, > is_newpatient, > visit_type, is_medical, >is_review, is_labtest, is_scan, > is_scopy, is_xray, > weight, height) >VALUES ((SELECT > coalesce(max(entry_no)+1, 1

Re: [SQL] concurrency problem

2006-06-16 Thread Aaron Bono
I would use a BIGSERIAL for the ID.  It simplifies your inserts, you don't have to mess with any locking and the sequence is maintained for you outside your transaction so two transactions can do inserts without stepping on each other. This is how I handle auto generated numbers.The only downside i

Re: [SQL] concurrency problem

2006-06-15 Thread Richard Huxton
sathish kumar shanmugavelu wrote: INSERT INTO rcp_patient_visit_monitor ( entry_no, patient_id, visit_date, is_newpatient, visit_type, is_medical, is_review, is_labtest, is_scan, is_scopy, is_xray, weight, height) VALUES ((SELECT c

Re: [SQL] Concurrency problem

2004-10-04 Thread Magnus Hagander
> Yes, I have several clients connecting to the db, using > the same username, doing the same things, pretty much. > > Please educate me: > When a table is accessed, is there an entry that is updated > in pg_catalog.pg_tables (or somewhere else) in such a fashion > that the MVCC ca

Re: [SQL] Concurrency problem

2004-10-04 Thread Dag Gullberg
Hi Tom, Yes, I have several clients connecting to the db, using the same username, doing the same things, pretty much. Please educate me: When a table is accessed, is there an entry that is updated in pg_catalog.pg_tables (or somewhere else) in such a fashion that the MVCC canno

Re: [SQL] Concurrency problem

2004-10-03 Thread Tom Lane
Dag Gullberg <[EMAIL PROTECTED]> writes: > Warning: pg_query(): Query failed: ERROR: tuple concurrently updated > CONTEXT: PL/pgSQL function "get_rights" line 5 at SQL statement in > /home/site/PHP/db_func.php on line 301 > Code of get_rights: > GRANT SELECT ON c.users TO > adm,w3;