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

Ken Mankoff mankoff at gmail.com
Thu Jan 12 18:40:00 PST 2017


Hi Stefan,

Your code didn't seem to work for me, but allowed me to figure out how to make it work. This does:

db.execute sql="UPDATE CTD_2015 SET YMD=date('2015-01-01', +CAST(DOY AS text) || ' days');"


I'm not sure why I can't simplify this to:

db.execute sql="UPDATE CTD_2015 SET YMD=date('2015-01-01', '+DOY days');"

But it is OK.

Thank you for the hint,

  -k.

On 2017-01-12 at 21:17, Blumentrath, Stefan <Stefan.Blumentrath at nina.no> wrote:
> Hi Ken,
>
> In SQLite it would look like this:

> SELECT substr(CAST(date('2015-01-01', +CAST(DOY -1 AS text) || '
> days') AS text), 6, 2);
>
> Or
>
> SELECT CAST(ltrim(substr(CAST(date(CAST(2015 AS text) || '-01-01',
> +CAST(2-1 AS text) || ' days') AS text), 6, 2), '0')as smallint)
>
> If you want numeric return.
>
> Thus, try:
>
> db.select sql="SELECT substr(CAST(date('2015-01-01', +CAST(134 -1 AS
> text) || ' days') AS text), 6, 2);"
>
> To see how it works...
>
> Then try something like:
>
> v.db.update map=CTD_2015 column=YMD value=
> substr(CAST(date('2015-01-01', +CAST(DOY -1 AS text) || ' days') AS
> text), 6, 2)
>
> or
>
> db.select sql="UPDATE CTD_2015 SET YMD =
> substr(CAST(date('2015-01-01', +CAST(134 -1 AS text) || ' days') AS
> text), 6, 2);"
>
> Cheers
> Stefan


More information about the grass-user mailing list