New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set a float value to NaN? #5194

Closed
gcatto opened this Issue Jan 12, 2016 · 7 comments

Comments

4 participants
@gcatto

gcatto commented Jan 12, 2016

This may totally be my problem, but I have a float value (with allowNull: false) that I would like to be able to see to NaN. However, when I do so, I get SequelizeDatabaseError: column \"nan\" does not exist. Is there a specific way I am supposed to provide NaN as a value? Thanks!

@mickhansen

This comment has been minimized.

Contributor

mickhansen commented Jan 12, 2016

Does your database support NaN as a value in any way?
My guess is you'd want to insert a null instead

@gcatto

This comment has been minimized.

gcatto commented Jan 12, 2016

Thanks for the fast response! I'm using Postgres and I can write a raw SQL query to insert NaN into the same column.

@gcatto

This comment has been minimized.

gcatto commented Jan 12, 2016

I could potentially use null (or perhaps another value), although I'd have to refactor things a bit I think, as I am currently using null to mean something else, so I'd prefer to avoid that route if possible.

And, to give a little more detail, I am using updateAttributes() to update a block of attributes (shocking, I know) within a transaction where one of the values can be NaN. Since the error is column \"nan\" does not exist that the NaN is being wrapped in "s instead of 's by the logic underneath updateAttributes()?

@mickhansen

This comment has been minimized.

Contributor

mickhansen commented Jan 12, 2016

Can you try pasting the SQL query Sequelize generated?
If Postgres supports NaN we should ideally support that aswell.

@gcatto

This comment has been minimized.

gcatto commented Jan 12, 2016

I've simplified out some of the other, irrelevant attributes from the code that gets generated:

INSERT INTO "foo" ("heuristics","id") VALUES (NaN,815) RETURNING *

So it looks like its not wrapping the NaN in anything, where it should be wrapping it in 's I think.

@janmeier janmeier closed this in c04c5ba Feb 21, 2016

@Volox

This comment has been minimized.

Volox commented Feb 24, 2016

Hi,
i have the same problem with Integer types.
@jamelt is there a reason to have the solution applied only to FLOAT, DOUBLE, REAL?

@janmeier

This comment has been minimized.

Member

janmeier commented Feb 24, 2016

@Volox NaN is only supported by IEEE floating point types, see http://www.postgresql.org/docs/8.4/static/datatype-numeric.html sector 8.1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment