[GRASS-user] v.extract features based on multiple SQL statements in one go

Hamish hamish_b at yahoo.com
Tue Jun 4 17:47:09 PDT 2013


Nikos wrote:
> Sidenote:  I am trying to trace a, maybe similar,
> action of mine some years ago, where Hamish pointed how
> inefficient my script-ing was, opening/executing 
> SQL/closing multiple times a file.  Can't locate it
> though.

if using db.execute or db.select or v.db.update in a loop,
it is better to write out a commands.sql text file, with each
request on one line of the file, and each line ending in a ";".
Then just call db.execute with input="commands.sql".

opening and closing the DB each time is expensive, so doing
it 1000 times for 1 operation each time is quite inefficient.
I'm not sure if it is fixed now, but until recently e.g.
'v.out.ascii columns=' opened and closed for each cat, meaning
it was unusable for > ~10k records. (use the v.out.ascii.db addon
script in that case)


also to remember that db.select can not execute anything, it
is a "read only" operation.


Hamish


More information about the grass-user mailing list