Subject Re: [ib-support] View performance
Author Ivan Prenosil
> > Computed field will be computed only when you select it. E.g.
> >
> > CREATE TABLE T (
> > pk INTEGER ...,
> > data1 COMPUTED (select data1 from spGetData1(T.pk)),
> > data2 COMPUTED (select data1 from spGetData2(T.pk)) );
> >
> > SELECT pk, data1 FROM T;
> >
> > -> only spGetData1(T.pk) will be computed, not spGetData2(T.pk).
> Strangely, I cannot seem to get the above COMPUTED field declaration to
> work. FB complains about token unknown 'select'. Apparently a computed
> field can only contain simple expressions (i.e. data1+data2). I have
> always thought that the 'expr' part could be anything as long as it is a
> singleton select....

For select statement to become expression, it has to be enclosed in parenthesis
(which I forgot in the example, sorry). So, it should be one pair of parenthesis
for COMUTED, one pair for SELECT:

CREATE TABLE T (
pk INTEGER ...,
data1 COMPUTED ( (select data1 from spGetData1(T.pk)) ),
data2 COMPUTED ( (select data1 from spGetData2(T.pk)) ) );


Ivan
http://www.volny.cz/iprenosil/interbase