Splunk Search

Any difference between NULL and null() in eval?

helge
Builder

In an eval expression, is there any difference between using NULL and null()?

Use case: I want to return null in an eval expression. I am finding that the following two expressions give the same result and I want to make sure that both are officially correct:

  • if (isnotnull (fieldX), fieldX * 10, NULL)
  • if (isnotnull (fieldX), fieldX * 10, null())
1 Solution

woodcock
Esteemed Legend

In the former case, you are setting it to the value of the field named NULL, which in your case, clearly doesn't exist right now HOWEVER that might not always be the case. It is equivalent to if(isnotnull(fieldX), fieldX*10, ThisFieldNameDoesNotExistSoTheValueThatItHasAlsoDoesNotExistSoRightNowThisEvaluatesToNULL). So it is very poor practice to use the former and you should use the latter.

View solution in original post

woodcock
Esteemed Legend

In the former case, you are setting it to the value of the field named NULL, which in your case, clearly doesn't exist right now HOWEVER that might not always be the case. It is equivalent to if(isnotnull(fieldX), fieldX*10, ThisFieldNameDoesNotExistSoTheValueThatItHasAlsoDoesNotExistSoRightNowThisEvaluatesToNULL). So it is very poor practice to use the former and you should use the latter.

helge
Builder

Now you mention it the answer is quite obvious 😉
Thanks!

0 Karma

DalJeanis
SplunkTrust
SplunkTrust

Ah yes, The Field Who Must Not Be Named...

Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...