Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8657037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:25:26+00:00 2026-06-12T15:25:26+00:00

I have a HSQL databse which is read by a 3rd party code. This

  • 0

I have a HSQL databse which is read by a 3rd party code. This 3rd party code translates certain numeric values to Double.NaN. My task is to write an sql query that can replace those numeric values with null.

At this item HSQLDB Statement and Java NaN doubles I read that sqrt(-1) or 0.0/0.0 will be translated to NaN. However, testing for equality works a bit odd for this values. Consider this query:

select
    casewhen(1=1, 1, 0), -- this one is to make sure that casewhen works as we expect
    casewhen(sqrt(-1)=sqrt(-1), 1, 0), -- this one looks good, we'll see
    casewhen(sqrt(-1)=1, 1, 0) -- this is the odd part, we'll see
from mytable; -- any table with at least 1 row will do

It returns rows like this:

C1 C2 C3
 1  1  1

Looks like sqrt(-1) is equal to every number. I could tweak it this way:

select
    casewhen(1=1, 1, 0),
    casewhen(
        position(
                 '0E0/0E0' in
                 cast(sqrt(-1) to varchar(40))
                ) = 1,
        'NaN', 'Numeric')
 from mytable;

It returns what I need:

C1  C2
 1 NaN

But I’m not satisfied: this solution needs a cast from numeric to varchar, then runs the position function and checks its return value to see if it would cast to NaN. Do you know a more effective solution on the SQL level?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:25:27+00:00Added an answer on June 12, 2026 at 3:25 pm

    I found a quicker workaround:

    select
        casewhen(5 = 5 + 1, 1, 0),
        casewhen(sqrt(-1) = sqrt(-1) , 1, 0)
    from mytable;
    

    Will return rows like this:

    C1 C2
     0  1
    

    So, the (x = x + 1) is only true for NaN values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have written this little class, which generates a UUID every time an object of
I have some integrtion tests that create an HSQL db from JPA entities. This
I have a HSQL database which Spring automatically creates for me: <jdbc:embedded-database id=dataSource type=HSQL>
We have a HSQL .script file in source control. Some of our developers use
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
Have 2 tables in Access 2007, both lists of certain tasks to be accomplished.
I have created an extremely simple junit test, which creates a null product in
Have a SQL problem, adding this model all works correctly, the problem is in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.