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

Nikos Alexandris nikos.alexandris at felis.uni-freiburg.de
Thu May 28 07:58:48 EDT 2009


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



More information about the grass-user mailing list