[GRASS-user] division in v.db.update or sql expression + db.execute results always "zero"

Hi list.

I am testing the following:

#using grass6_dev, compiled some weeks ago
# with v.db.update
v.db.update sample_1 column=exprtest value="burned/reference"

# sql expression
echo "UPDATE sample_1_grid_points SET exprtest=burned_pix / 10" |
db.execute

and I always get a "0". Multiplication, addition and subtraction work
fine but division seems not.

Looking for pointers with respect to division and v.db.update/ SQL
expression + db.execute, I have found in the archive some posts of
Moritz [1]. Is this (still) a bug?

Kind regards, Nikos

[1] http://n2.nabble.com/Fwd%
3A-calculate-values-of-an-attribute-table-column-tc1885693.html#a1885698

Nikos:

#using grass6_dev, compiled some weeks ago

...

# sql expression
echo "UPDATE sample_1_grid_points SET exprtest=burned_pix / 10" |
db.execute

and I always get a "0". Multiplication, addition and subtraction work
fine but division seems not.

Not always. The problem is that the decimals are not printed so I see
only the leading 0 and the ".xxx" is missing.

For example:

* column "burned_pix" has min=1, max=281
* division by 10 gives numbers from 0 to 28
* division by 100 gives numbers from 0 to 2

successively, division with a denominator > nominator _prints-out_ zero
as a result.

Before testing with spearfish...

...Is this a bug?

Nikos

[1] http://n2.nabble.com/Fwd%
3A-calculate-values-of-an-attribute-table-column-tc1885693.html#a1885698

Nikos:

> #using grass6_dev, compiled some weeks ago
...
> # sql expression
> echo "UPDATE sample_1_grid_points SET exprtest=burned_pix / 10" |
> db.execute

> and I always get a "0". Multiplication, addition and subtraction work
> fine but division seems not.

Not always. The problem is that the decimals are not printed so I see
only the leading 0 and the ".xxx" is missing.

quoting Hamish:
<
try "/ 10.0", then it may output floating point number instead of
integer. (int/int gives int as a result in many programming languages)

Indeed, it's a matter of integer output. To exemplify, the following sql
expression works fine:

# multiply integer columns by "1."
echo " UPDATE sample_1_grid_points SET burned_percent = (burned_pix *
1. / reference_pix *1. ) * 100 " | db.execute

It'll be useful to have an example in v.db.update/ db.execute man pages.
Kindest regards, Nikos