Subject | Re: update from select |
---|---|
Author | Milan Babuskov |
Post date | 2007-08-20T11:44:13Z |
--- Nick Upson wrote:
performance-wise. If you have a lot of records, writing a stored
procedure (or EXECUTE BLOCK with Firebird 2) should be better:
EXECUTE BLOCK
AS
DECLARE VARIABLE c1...
DECLARE VARIABLE c2...
DECLARE VARIABLE c3... etc. for each column
BEGIN
for select c1, c2, c3, ...
from table1
into :c1, :c2, :c3...
do update table2 set c1 = :c1, c2 = :c2, ... where pk = :pk;
END
If you use Firebird 1.x or don't want to waste time writing such
procedures, you can use FBExport to do the job for you, by using -If
option. Example:
fbexport -Q "select field1, field2, ... from table1"
fbexport -If "update table2 set field1 = :1, field2 = :2 ... where..."
--
Milan Babuskov
http://fbexport.sourceforge.net
> I got "update table1 set field1 = (select field2 from table2 whereYou could do what sasha wrote, although it is not very good
> ...)" but I have about 12 fields involved.
>
> Could someone more awake please post an example
performance-wise. If you have a lot of records, writing a stored
procedure (or EXECUTE BLOCK with Firebird 2) should be better:
EXECUTE BLOCK
AS
DECLARE VARIABLE c1...
DECLARE VARIABLE c2...
DECLARE VARIABLE c3... etc. for each column
BEGIN
for select c1, c2, c3, ...
from table1
into :c1, :c2, :c3...
do update table2 set c1 = :c1, c2 = :c2, ... where pk = :pk;
END
If you use Firebird 1.x or don't want to waste time writing such
procedures, you can use FBExport to do the job for you, by using -If
option. Example:
fbexport -Q "select field1, field2, ... from table1"
fbexport -If "update table2 set field1 = :1, field2 = :2 ... where..."
--
Milan Babuskov
http://fbexport.sourceforge.net