Here is the documentation for the LIKE operator in SQLite: https://www.sqlitetutorial.net/sqlite-like/
It should be possible to use it in a “searched case statement”: https://www.sqlitetutorial.net/sqlite-case/ So the syntax would be: db.execute sql="UPDATE myroads SET width=CASE WHEN TYPE LIKE 'M%' THEN 'Wide' WHEN TYPE LIKE 'Loc%' THEN 'Narrow' ELSE 'Unknown' END;" Cheers Stefan From: grass-user <[email protected]> On Behalf Of Margherita Di Leo Sent: onsdag 17. juni 2020 18:39 To: Micha Silver <[email protected]> Cc: GRASS user list <[email protected]> Subject: Re: [GRASS-user] Reclassify a vector adding a column Dear Micha, On Wed, Jun 17, 2020 at 4:05 PM Micha Silver <[email protected]<mailto:[email protected]>> wrote: On 17/06/2020 16:14, Margherita Di Leo wrote: Ciao Stefan, thank you, I tried and it didn't give me any error but didn't update the column either... The sqlite CASE statement should be: CASE <old_column> WHEN '<old_val1>' THEN '<new_val1>' WHEN '<old_val2>' THEN '<new_val2>'....END; Here's an example that worked for me. I have a "myroads" vector with column 'TYPE' # Add new column for road width as text v.db.addcolumn myroads column="width TEXT" # Run update with CASE db.execute sql="UPDATE myroads SET width=CASE TYPE WHEN 'Main' THEN 'Wide' WHEN 'Local' THEN 'Narrow' ELSE 'Unknown' END;" Best, Micha This worked! Thank you so much! I have one last question. Does it also support an IS LIKE condition, and if yes, how can I express it? Thanks! -- Margherita Di Leo
_______________________________________________ grass-user mailing list [email protected] https://lists.osgeo.org/mailman/listinfo/grass-user
