Le 12 janvier 2017 17:49:12 GMT+01:00, Ken Mankoff <[email protected]> a écrit : >Hi Helmut, > >I misspoke and the data column I'm working with is not Julian Day (JD) >but Day of Year (DOY). I looked at the SQL datetime functions and can't >find a way to convert DOY to YYY-MM-DD. Can you help with this? > >Also, you are correct, these modules do not work with bash. Is there >any way to populate a column with something other than SQL? I think SQL >is Turing complete and therefore can be used for arbitrarily complex >functions, but it doesn't seem like the right tool in this case. There >are simple bash commands that can generate the data, but I have no way >to get that data into the column without a for loop, which is >computationally slow. My current solution is: > ># extract the category (unique) and the DOY column (1 and 13) >for cat_DOY in $(db.select table=CTD_2015| cut -d"|" -f1,13); do > # separate into category and DOY > cat=$(echo $cat_DOY | cut -d"|" -f1) > DOY=$(echo $cat_DOY | cut -d"|" -f2) > YMD=$(doy2ymd 2015 ${DOY}) > v.db.update map=CTD_2015 column=YMD where="cat = ${cat}" value=${YMD} >done
It should be possible to do this directly in SQL, but if not you might want to modify your script to write complete SQL UPDATE statements for each cat_DOY to a file (instead of the v.db.update calls) and then, once the loop is done, feed that file to db.execute. This will probably be faster. Moritz > >Thanks, > > -k. > >On 2017-01-12 at 14:56, Helmut Kudrnovsky <[email protected]> wrote: >> Helmut Kudrnovsky wrote >>>>Neither db.execute nor db.select appear to work with arbitrary bash >> commands. >>> >>> AFAIK these modules need a SQL statement, not a bash command; e.g. >[1]: >>> db.execute - Executes any SQL statement. >>> >>> >>> [1] https://grass.osgeo.org/grass73/manuals/db.execute.html >> >> there are some sqlite Date And Time Functions: >> https://www.sqlite.org/lang_datefunc.html >> >> >> >> ----- >> best regards >> Helmut > >_______________________________________________ >grass-user mailing list >[email protected] >http://lists.osgeo.org/mailman/listinfo/grass-user _______________________________________________ grass-user mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/grass-user
