Now() is sometimes not a function?

I want to know when the latest data point is for each value of some other field, and how old it is. Here’s the query I wrote:

select now() - time, last("temperature") from temps group by location;

But I get

ERR: undefined function now()

which seems odd because I can use that expression in the “where” clause:

select last("temperature") from temps where time < now() - 60m group by location;

For what it’s worth, it doesn’t work any better if I apply an aggregate function to time, as follows:

select now() - time, last("temperature") from temps group by location;

I wonder

(a) Why can’t it simply calculate now() - time for each row in the result? But more importantly
(b) Is there another way to reach my goal, to get the age of the latest data points after grouping?

I should clarify: The thing I want to “groupy by” is a tag, not a field. So the grouping, I believe, should be fairly efficient. The problem with certain uses of now() remains.

@ezquat Did you fixed this, I have the same issue.

@daochun_zhao I never solved it, or found a workaround, alas!

Probably best to report as a bug on the slack channel regarding flux, or something.

1 Like

In another thread, @anaisdg explains this can’t be done in InfluxQL but it can be done in Flux: How to get how much time elapsed since data point is stored in influxdb