[GRASS-user] db.execute: SELECT STATEMENT

Jarek Jasiewicz jarekj at amu.edu.pl
Tue Jan 30 14:00:19 EST 2007


Wolf Bergenheim napisał(a):
> Markus Neteler wrote:
>> Right - which is confusing since the module says:
>> "db.execute  - Execute any SQL statement"
>> apparently wrong? Or a bug?
>
> This is a case of programing technique showing in the UI. Normally in 
> programming with databases, there are two kind of queries you can give 
> to a database. All (well almost, there might be some exception) DB 
> APIs give the programmer 2 functions execute and select. The select 
> function usually return a dataset - the response to the query, while 
> the execute just returns a success flag, since this function is used 
> to execute statements like UPDATE, DELETE, INSERT etc. A good UI would 
> hide this distinction based on the query.
>
>> For now, just use db.select instead.
>> But we should solve this confusion.
>>> I add, that combination can be execute in pgadmin without problem so 
>>> statements are good
>> It seems to be a (mysterious to me) limitation in db.execute.
>
> So either fix db.execute to call a select function instead, or even 
> db.select if it gets a SELECT statement to execute? Otherwise fix 
> documentation, meaning that the manual and help should say "...EXECUTE 
> any non-SELECT statement. Use db.select to execute SELECT statements." 
> Or something like that.
>
> --Wolf
>
But what about this (sample test query):

echo "UPDATE testpoint_2 SET test=(SELECT max(cat) FROM testpoint_1) 
WHERE cat IN (SELECT cat FROM testpoint_3 WHERE x>10)" | db.execute

it works! AFAIK such quries are treated as both SELECT and UPDATE query!

regards
Jarek





More information about the grass-user mailing list