dbTalk Databases Forums  

Updating multiple tables "simultaneously"

comp.databases.postgresql comp.databases.postgresql


Discuss Updating multiple tables "simultaneously" in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #41  
Old   
Ronald Raygun
 
Posts: n/a

Default Re: Updating multiple tables "simultaneously" - 04-01-2008 , 06:39 AM






Thanks Andreas,

I am making some progress on this now. I have worked out the constituent
logic - and which unctions to use (thanks to your feedback). The
remaining challenge is how to put it all together into valid SQL.

Here is the logic I have so far:


I think I can seperate the field values of (rows) by commas and then
separate the rows themselves using semicolumns, so that an example book
details argument could look like this:

"1,'Romeo & Juliet', 'W. Shakespeare'; 2, 'The Art of War', 'Sun Tzu";
3, 'War & Peace', 'Leo Tolstoy"

So I can first parse the string into string array (i.e. 3 rows), by
splitting on ';' then I iterate through each string (row), get the
values for each field, build a string and then execute an INSERT INTO
statement, using the value extracted from the row.

Having got this far, the problems then are:

1). How to create an 'INSERT INTO statement from each of the rows
(declare a string variable in SQL?)?
2). How to execute the 'INSERT INTO' statement from my function?
3). How to know if the INSERT failed?
4). How to ROLLBACK if an error occured in ANY of the row inserts?

Reply With Quote
  #42  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: Updating multiple tables "simultaneously" - 04-01-2008 , 06:58 AM






begin Ronald Raygun schrieb:
Quote:
Having got this far, the problems then are:

1). How to create an 'INSERT INTO statement from each of the rows
(declare a string variable in SQL?)?
You can do that, and EXECUTE the string:

http://www.postgresql.org/docs/8.1/i...-EXECUTING-DYN

Quote:
2). How to execute the 'INSERT INTO' statement from my function?
3). How to know if the INSERT failed?
http://www.postgresql.org/docs/8.1/i...TS-DIAGNOSTICS


Quote:
4). How to ROLLBACK if an error occured in ANY of the row inserts?
You can try to COMMIT after the function, if there was an error a
ROLLBACK performed instead.


end
Andreas
--
Andreas Kretschmer
Linux - weil ich es mir wert bin!
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net


Reply With Quote
  #43  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: Updating multiple tables "simultaneously" - 04-01-2008 , 06:58 AM



begin Ronald Raygun schrieb:
Quote:
Having got this far, the problems then are:

1). How to create an 'INSERT INTO statement from each of the rows
(declare a string variable in SQL?)?
You can do that, and EXECUTE the string:

http://www.postgresql.org/docs/8.1/i...-EXECUTING-DYN

Quote:
2). How to execute the 'INSERT INTO' statement from my function?
3). How to know if the INSERT failed?
http://www.postgresql.org/docs/8.1/i...TS-DIAGNOSTICS


Quote:
4). How to ROLLBACK if an error occured in ANY of the row inserts?
You can try to COMMIT after the function, if there was an error a
ROLLBACK performed instead.


end
Andreas
--
Andreas Kretschmer
Linux - weil ich es mir wert bin!
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net


Reply With Quote
  #44  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: Updating multiple tables "simultaneously" - 04-01-2008 , 06:58 AM



begin Ronald Raygun schrieb:
Quote:
Having got this far, the problems then are:

1). How to create an 'INSERT INTO statement from each of the rows
(declare a string variable in SQL?)?
You can do that, and EXECUTE the string:

http://www.postgresql.org/docs/8.1/i...-EXECUTING-DYN

Quote:
2). How to execute the 'INSERT INTO' statement from my function?
3). How to know if the INSERT failed?
http://www.postgresql.org/docs/8.1/i...TS-DIAGNOSTICS


Quote:
4). How to ROLLBACK if an error occured in ANY of the row inserts?
You can try to COMMIT after the function, if there was an error a
ROLLBACK performed instead.


end
Andreas
--
Andreas Kretschmer
Linux - weil ich es mir wert bin!
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net


Reply With Quote
  #45  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: Updating multiple tables "simultaneously" - 04-01-2008 , 06:58 AM



begin Ronald Raygun schrieb:
Quote:
Having got this far, the problems then are:

1). How to create an 'INSERT INTO statement from each of the rows
(declare a string variable in SQL?)?
You can do that, and EXECUTE the string:

http://www.postgresql.org/docs/8.1/i...-EXECUTING-DYN

Quote:
2). How to execute the 'INSERT INTO' statement from my function?
3). How to know if the INSERT failed?
http://www.postgresql.org/docs/8.1/i...TS-DIAGNOSTICS


Quote:
4). How to ROLLBACK if an error occured in ANY of the row inserts?
You can try to COMMIT after the function, if there was an error a
ROLLBACK performed instead.


end
Andreas
--
Andreas Kretschmer
Linux - weil ich es mir wert bin!
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net


Reply With Quote
  #46  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: Updating multiple tables "simultaneously" - 04-01-2008 , 06:58 AM



begin Ronald Raygun schrieb:
Quote:
Having got this far, the problems then are:

1). How to create an 'INSERT INTO statement from each of the rows
(declare a string variable in SQL?)?
You can do that, and EXECUTE the string:

http://www.postgresql.org/docs/8.1/i...-EXECUTING-DYN

Quote:
2). How to execute the 'INSERT INTO' statement from my function?
3). How to know if the INSERT failed?
http://www.postgresql.org/docs/8.1/i...TS-DIAGNOSTICS


Quote:
4). How to ROLLBACK if an error occured in ANY of the row inserts?
You can try to COMMIT after the function, if there was an error a
ROLLBACK performed instead.


end
Andreas
--
Andreas Kretschmer
Linux - weil ich es mir wert bin!
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net


Reply With Quote
  #47  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: Updating multiple tables "simultaneously" - 04-01-2008 , 06:58 AM



begin Ronald Raygun schrieb:
Quote:
Having got this far, the problems then are:

1). How to create an 'INSERT INTO statement from each of the rows
(declare a string variable in SQL?)?
You can do that, and EXECUTE the string:

http://www.postgresql.org/docs/8.1/i...-EXECUTING-DYN

Quote:
2). How to execute the 'INSERT INTO' statement from my function?
3). How to know if the INSERT failed?
http://www.postgresql.org/docs/8.1/i...TS-DIAGNOSTICS


Quote:
4). How to ROLLBACK if an error occured in ANY of the row inserts?
You can try to COMMIT after the function, if there was an error a
ROLLBACK performed instead.


end
Andreas
--
Andreas Kretschmer
Linux - weil ich es mir wert bin!
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net


Reply With Quote
  #48  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: Updating multiple tables "simultaneously" - 04-01-2008 , 06:58 AM



begin Ronald Raygun schrieb:
Quote:
Having got this far, the problems then are:

1). How to create an 'INSERT INTO statement from each of the rows
(declare a string variable in SQL?)?
You can do that, and EXECUTE the string:

http://www.postgresql.org/docs/8.1/i...-EXECUTING-DYN

Quote:
2). How to execute the 'INSERT INTO' statement from my function?
3). How to know if the INSERT failed?
http://www.postgresql.org/docs/8.1/i...TS-DIAGNOSTICS


Quote:
4). How to ROLLBACK if an error occured in ANY of the row inserts?
You can try to COMMIT after the function, if there was an error a
ROLLBACK performed instead.


end
Andreas
--
Andreas Kretschmer
Linux - weil ich es mir wert bin!
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net


Reply With Quote
  #49  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: Updating multiple tables "simultaneously" - 04-01-2008 , 06:58 AM



begin Ronald Raygun schrieb:
Quote:
Having got this far, the problems then are:

1). How to create an 'INSERT INTO statement from each of the rows
(declare a string variable in SQL?)?
You can do that, and EXECUTE the string:

http://www.postgresql.org/docs/8.1/i...-EXECUTING-DYN

Quote:
2). How to execute the 'INSERT INTO' statement from my function?
3). How to know if the INSERT failed?
http://www.postgresql.org/docs/8.1/i...TS-DIAGNOSTICS


Quote:
4). How to ROLLBACK if an error occured in ANY of the row inserts?
You can try to COMMIT after the function, if there was an error a
ROLLBACK performed instead.


end
Andreas
--
Andreas Kretschmer
Linux - weil ich es mir wert bin!
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.