Subject | Re: Computed Column |
---|---|
Author | Werner F. Bruhin |
Post date | 2003-08-25T13:50:19Z |
Hi Helen and Martijn,
Thanks for the quick reply and sorry for not having giving enough detail.
--- In firebird-support@yahoogroups.com, "Martijn Tonies"
<m.tonies@u...> wrote:
Create a table as:
CREATE TABLE "computedby" (
F1 INTEGER,
F2 INTEGER,
F3 COMPUTED BY (F1-F2)
);
INSERT INTO "computedby" (F1, F2) VALUES (2, 1);
F3 will compute with result of 2 - 1 = 1
INSERT INTO "computedby" (F1) VALUES (1);
F3 will NOT compute!
In the meantime I figured out a way to work around it by defining a
default of Zero for both F1 and F2.
Thanks for the quick reply and sorry for not having giving enough detail.
--- In firebird-support@yahoogroups.com, "Martijn Tonies"
<m.tonies@u...> wrote:
> Hi Werner,Do the following you will see:
>
>
> > Have a table with column quantityonhand which is computed.
> >
> > COMPUTED BY (quantitypurchased-quantityconsumed)
> >
> > Now the problem I have is that the column does NOT compute when I
> > update one of the two columns (purchased or consumed).
>
> What do you mean with "does not compute"? A COMPUTED BY
> expressesion is evaluated on every row retrieval, it ALWAYS computes.
Create a table as:
CREATE TABLE "computedby" (
F1 INTEGER,
F2 INTEGER,
F3 COMPUTED BY (F1-F2)
);
INSERT INTO "computedby" (F1, F2) VALUES (2, 1);
F3 will compute with result of 2 - 1 = 1
INSERT INTO "computedby" (F1) VALUES (1);
F3 will NOT compute!
In the meantime I figured out a way to work around it by defining a
default of Zero for both F1 and F2.
>
> > Both columns are defined as Int and the computed column is BigInt, and
> > all have no default.
> >
> > When I update from a Python program with kinterbasdb the computed
> > column is not updated.
>
> Mind you, the result of a COMPUTED BY isn't stored.
>
> Make sure you do a re-select after you've updated columns and that
> your transactions is finished, and/or your transaction isolation makes
> sense.
>
>
> With regards,
>
> Martijn Tonies
> Database Workbench - the developer tool for InterBase & Firebird
> Upscene Productions
> http://www.upscene.com