[GRASS-user] update column w/ output from bash function

Helmut Kudrnovsky hellik at web.de
Thu Jan 12 09:20:42 PST 2017


Ken Mankoff wrote
> 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
> 
> Thanks,

never done datetime conversions in sqlite for myself; a quick search in the
internet gives some examples for sqlite builtin conversion methods:

e.g.

https://www.sqlite.org/lang_datefunc.html
there are some examples also in there

e.g.
https://www.tutorialspoint.com/sqlite/sqlite_date_time.htm
date(timestring, modifiers...)	This returns the date in this format:
YYYY-MM-DD

sqlite> SELECT date('now','start of month','+1 month','-1 day');
2013-05-31

e.g.
http://stackoverflow.com/questions/650480/get-month-from-datetime-in-sqlite

HTH




-----
best regards
Helmut
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/update-column-w-output-from-bash-function-tp5303075p5303236.html
Sent from the Grass - Users mailing list archive at Nabble.com.


More information about the grass-user mailing list