Subject | RE: [firebird-support] Re: update from select |
---|---|
Author | sasha |
Post date | 2007-08-20T13:06:07Z |
> --- Nick Upson wrote:You are right Milan, stored procedure is faster (by far), but if you have to
> > I got "update table1 set field1 = (select field2 from table2 where
> > ...)" but I have about 12 fields involved.
> >
> > Could someone more awake please post an example
>
> You could do what sasha wrote, although it is not very good
> 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
>
select from different tables then it should be more or less the same. I
guess I haven't gave it any though, since I've spent a last couple of days
writting similar updates, and yes when you run those queries on largish sets
you suddenly find some free time while you're waiting on results... :)
Sasha