How to write functions and call them in NRQL?

Is there a way to compare two timestamps ? something like min(timestamp) == max(timestamp) ?

Hi @riaumapathy - Not sure what you are after, perhaps provide a pseudo-query or what you have so far with any sensitive information removed?

@riaumapathy would you be able to provide an example query? For reference, here are the components you can use:

@gjohnson @stefan_garnham
Example Query -
SELECT (min(timestamp) AS First_occurrence, max(timestamp) AS Last_occurrence, COUNT(*)) from TransactionError WHERE appName = 'staging - staging-oregon-docker/application' AND httpResponseCode='500' AND min(timestamp) = Time.now AND max(timestamp) = Time.now facet error.class, error.message, transactionName SINCE 1 week ago LIMIT 2000

Use case - Need to fetch the new transaction errors that has not occurred in the past 7 days[1 week ago] and should send slack notification as and when we notice such errors

Eg- First occurrence of an error will be calculated as min(timestamp), Last occurrence of an error will be calculated as max(timestamp). [Timeframe is one week]
Lets say Error A has not occurred in the past 7 days…
If Error A occurs today… i.e now, then we should send a slack notification with the details of that error.

Implementation plan we have is -
First occurrence and last occurrence should be equal to current timestamp… if so, then we should send a notification

Why we are comparing first occurrence, last occurrence and current timestamp is bcoz, if an error occurs now, we’ll send a notification… if the same error occurs again after 3 hrs in the same day, we should not send notification… If we send notification for the same error repeatedly, then the group will be flooded with error notification… to avoid that we planned to compare first and last occurrence with current timestamp.

Error First occurrence Last occurrence
Error A Oct 13,12.00pm. Oct 13,12.00pm. Send notification.
Error A Oct 13,12.00pm. Oct 13,3.00pm. Shoud not send notification

Problem -
Issue1# - Unable to get the current timestamp
Issue2# - Unable to compare First occurrence of the error[min(timestamp)] with current timestamp

I am not sure that you can perform that sort of analysis in a single NRQL query.

@stefan_garnham Is there any other way to perform this kind of analysis in Newrelic

If so, can you please help us