Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store NaN values in SQLite database

I'd like to insert NaN values into SQLite database.

I have Ent table with Id, StringColumn and DoubleColumn (not nullable) and I try use the following SQL statement:

INSERT INTO Ent (Id, StringColumn, DoubleColumn) VALUES (1, 'NaN test', ????)

I don't know what to put in place of '????' to have NaN stored.

I'm accessing the database using System.Data.SQLite - maybe this also matters?

like image 639
Dariusz Wasacz Avatar asked Mar 22 '13 11:03

Dariusz Wasacz


People also ask

How do I allow null values in SQLite?

Following is the basic syntax of using NULL while creating a table. SQLite> CREATE TABLE COMPANY( ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL ); Here, NOT NULL signifies that the column should always accept an explicit value of the given data type.

Does SQLite allow null in primary key?

Unless the column is an INTEGER PRIMARY KEY or the table is a WITHOUT ROWID table or a STRICT table or the column is declared NOT NULL, SQLite allows NULL values in a PRIMARY KEY column.

What does SQLite return if nothing is found?

If the result is NULL, then sqlite3_column_bytes() returns zero.

How does SQLite store integers?

The INTEGER values in SQLite are stored in either 1, 2, 3, 4, 6, or 8 bytes of storage depending on the value of the number. REAL – this storage class is used to store the floating point values, and they are stored in an 8-bytes of storage.


3 Answers

I've asked guys of SQLite how to deal with the problem: http://system.data.sqlite.org/index.html/tktview/e06c4caff3c433c80616ae5c6df63fc830825e59. They've added a new connection flag: "GetAllAsText" and now it is possible to store NaN, along with the others (Infinity, -Infinity).

like image 170
Dariusz Wasacz Avatar answered Oct 17 '22 20:10

Dariusz Wasacz


SQLite is rather... lax... about data types. Feel free to put "NaN" into a column defined as "double". Or "infinity". Or "double", for that matter. SQLite doesn't care.

like image 43
Dave Sherohman Avatar answered Oct 17 '22 18:10

Dave Sherohman


SQLite does not have a textual representation of NaN values.

In SQL, the special NULL behaves similarly in computations, and can serve the same purpose.

like image 23
CL. Avatar answered Oct 17 '22 20:10

CL.