SQLite Forum

sqlite3 rounding off the values of timestamp causing issues
Login
Hi,
I am facing issues with the database values after converting a sqlite2 database to sqlite3.

To provide some context, I have a table XYZ and it has a few rows that stores timestamps.

The structure of the table is,
CREATE TABLE "xyz" (
	"xyz_id"	INTEGER NOT NULL,
	"xyz_value"	VARCHAR NOT NULL,
	"xyz_order"	INTEGER DEFAULT 0
);

The column xyz_value is a VARCHAR and I read and write it as a string.
Although, while converting the db from sqlite2-3, I went ahead with the below approach,

# # sqlite mydata.db .dump | sqlite3 new_mydataV3.db

This did convert the db to sqlite3 but part of the code in my application that handles timestamp fails as the timestamp in the xyz_value was rounded off during this conversion.

I tried dumping the sqlite2 db to a file and examining if the values were rounded off to begin with. The dump file appears to be fine and has the values intact.

To reproduce the issue,

Create a table in sqlite2,

# # cat dump.sql
CREATE TABLE "value_tbl" ( "value_id"   INTEGER NOT NULL,"value_value"  VARCHAR NOT NULL,"value_order"  INTEGER DEFAULT 0);
INSERT INTO value_tbl VALUES(1,1536273869.654473892,0);
COMMIT;

# # sqlite new.db < dump.sql
# # sqlite new.db .dump
CREATE TABLE "xyz" ( "xyz_id"   INTEGER NOT NULL,"xyz_value"  VARCHAR NOT NULL,"xyz_order"  INTEGER DEFAULT 0);
INSERT INTO xyz VALUES(1,1536273869.654473892,0);
COMMIT;

The values seem intact over here.

Now converting it,

# # sqlite new.db .dump | sqlite3 newV3.db
# # sqlite3 newV3.db .dump
CREATE TABLE IF NOT EXISTS "xyz" ( "xyz_id"     INTEGER NOT NULL,"xyz_value"  VARCHAR NOT NULL,"xyz_order"  INTEGER DEFAULT 0);
INSERT INTO xyz VALUES(1,'1536273869.65447',0);
COMMIT;

The value was rounded off to 15 decimals.

The floating point does have an accuracy upto 15 digits but we know from the metadata of table, the values are strings. Why are we rounding the values to 15 digits?