How to convert string type to int type in NRQL

I want to limit some data via a column but the column type is string, I can’t use like column > ‘5’ way to limit, so I don’t know if there are some method/way to convert string to int type.

1 Like

Hi @ligang_yao,

There’s no way to convert types with Insights. This would need to be done at application level by adding a custom attribute for the value you want as an integer (it will actually be stored as a float).

This guide on our docs site has the information you’d need to insert custom attributes to Insights: https://docs.newrelic.com/docs/insights/new-relic-insights/decorating-events/insights-custom-attributes

I moved a post to a new topic: Convert existing parameters into an integer

Looks like numeric(column) > 5 should be supported now.

4 Likes

Should include the reference for the new functions

https://docs.newrelic.com/docs/insights/nrql-new-relic-query-language/nrql-reference/nrql-syntax-components-functions#h2-type-conversion-functions

1 Like

Yup! Thanks for sharing @6MM :slight_smile:

How can I use this for faceting?

FACET numeric(appVersion)

doesn’t seem to work

Hi, @apinho1: Does it need to be numeric in order to FACET? You should be able to FACET on a string:

FACET appVersion

Is there a function to force numerics to convert to string? I am noticing that in Insights some numbers are returned as int but then become floats when queried from GraphQL api. This happens even on ID fields (e.g. mutingId from NrAiIncident) so now I’m finding that I have to manuall strip off the trailing “.0” at the end of these IDs. For IDs would be easier if I could just force NRQL to convert to string so that GraphQL can’t tack on a “.0”

Hey there @garrett.scholtes,

Welcome back, its good to see you in the community again!

You may view all NRQL statements and functions here: NRQL syntax, clauses, and functions | New Relic Documentation.

Looking over the doc you will see that NRQL does not have any string functions. Please let me know if this was helpful and answered your question and if not reach out and we will continue to provide support. I hope you have a great day!