Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread Default value not triggering computed value
Sun, Apr 27 2008 9:05 AMPermanent Link

Uli Becker
I have these fields in a table (translated fieldnames):

Count: integer default = 1;
Factor: float;
Price: float;
Sum: float generated (Count * Factor * Price);

When inserting some thousands of test records by using stored procedure
I noticed some hundred null-values in the field "Sum". I had a hard time
to find what caused the problem:

  Insert into posten (Count, Factor, Price) values (?, ?,?);
  execute stmt using 1, MyFactor, MyPrice;

works and gives the correct sum

whereas

  Insert into posten (Factor, Price) values (?,?);
  execute stmt using MyFactor, MyPrice;

works (Count = 1 by default) but the sum is null.

I guess it's a timing problem when the result of "sum" is calculated.

Regards Uli
Sun, Apr 27 2008 12:23 PMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Uli,

The default value is being stored in the column after the value for
"Sum" is generated, and I can't say if this is "as designed" or not -
Tim can later clarify this - meanwhile, you can set the generation
expression for the "Sum" column to:

COALESCE(Count, 1) * Factor * Price

--
Fernando Dias
[Team Elevate]
Sun, Apr 27 2008 2:02 PMPermanent Link

Uli Becker
Fernando,

> COALESCE(Count, 1) * Factor * Price

Good workaround! My compliments. Thank you.

Regards Uli
Mon, Apr 28 2008 8:38 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Uli,

It is exactly as Fernando indicates.  However, I can change around the
sequence so that the defaults are populated first, but I will have to
double-check on this to make sure that there aren't any scenarios where this
could be a problem.  I don't think most people would need a default value
for a generated column, but it pays to be careful with this type of thing.
Smiley

--
Tim Young
Elevate Software
www.elevatesoft.com

Mon, Apr 28 2008 9:52 AMPermanent Link

Uli Becker
Tim
> It is exactly as Fernando indicates.  However, I can change around the
> sequence so that the defaults are populated first, but I will have to
> double-check on this to make sure that there aren't any scenarios where this
> could be a problem.  I don't think most people would need a default value
> for a generated column, but it pays to be careful with this type of thing.
> Smiley

Thanks. No need to change anything. With the coalesce-function it works
fine. It's just important to know about.

Regards Uli
Mon, Apr 28 2008 1:42 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Uli,

<< Thanks. No need to change anything. With the coalesce-function it works
fine. It's just important to know about. >>

Yeah, I've been beating this around today in my head, and it seems that
there might be a case where someone with a generated column will still want
a default value.  It would be rare, probably, but a generated column is
supposed to behave just like a normal column, except for the "generated"
part. Smiley

--
Tim Young
Elevate Software
www.elevatesoft.com

Image