Skip to content

Impossible to insert a Double.NaN value #217

Closed

Description

@Tradioyes

This is a regression from 2.0.13-beta1.
I tried to upgrade to 2.1.3 and Npgsql crashed when I try to insert a NaN value in a double precision field.
The error is:
Npgsql.NpgsqlException : ERROR: 42703: column "nan" does not exist

The first tests works, the second raises the error.

    [Test]
    public void HandleDoubleValueParameter()
    {
        ExecuteNonQuery(@"CREATE TABLE dataDouble (
                            field_double                  double precision
                            )");
        try
        {
            var command = new NpgsqlCommand("insert into dataDouble(field_double) values (:a)", Conn);
            command.Parameters.Add(new NpgsqlParameter("a", NpgsqlDbType.Double));
            command.Parameters[0].Value = 123.456;
            var query = command.CommandText;
            var rowsAdded = command.ExecuteNonQuery();
            Assert.AreEqual(1, rowsAdded);
        }
        finally
        {
            ExecuteNonQuery(@"DROP TABLE dataDouble");
        }
    }

    [Test]
    public void HandleDoubleNanValueParameter()
    {
        ExecuteNonQuery(@"CREATE TABLE dataDouble (
                            field_double                  double precision
                            )");

        try
        {
            var command = new NpgsqlCommand("insert into dataDouble(field_double) values (:a)", Conn);
            command.Parameters.Add(new NpgsqlParameter("a", NpgsqlDbType.Double));
            command.Parameters[0].Value = double.NaN;
            var query = command.CommandText;
            var rowsAdded = command.ExecuteNonQuery();
            Assert.AreEqual(1, rowsAdded);
        }
        finally
        {
            ExecuteNonQuery(@"DROP TABLE dataDouble");
        }
    }

Activity

  1. franciscojunior commented on Apr 17, 2014

    @franciscojunior
    Member

    I'll check that. Thanks for your report!

  2. added this to the milestone on Apr 17, 2014
  3. franciscojunior commented on Jun 10, 2014

    @franciscojunior
    Member

    Sorry for late reply.

    Indeed this regression was caused by changes in the way we send the data to the server.

    For while, a workaround is to use a prepared statement.

    I'm working on a fix.

  4. added a commit that references this issue on Jul 12, 2014
    3f01e79
  5. roji commented on Jul 30, 2014

    @roji
    Member

    @franciscojunior, this is one of the last issues for 2.2 Is it a duplicate of #257? Are you working on it or is @glenebob?

  6. franciscojunior commented on Jul 30, 2014

    @franciscojunior
    Member

    @franciscojunior, this is one of the last issues for 2.2 Is it a duplicate of #257? Are you working on it or is @glenebob?

    I asked @glenebob to have a look at it. He said he will look on this weekend.
    #257 is the pull request with my fix for this issue.

  7. added a commit that references this issue on Aug 3, 2014
    bcdd3c8
  8. added theissue type on Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions