http://www.sqlite.org/datatype3.html#type_affinity

The key sentence in that section is
"SQLite considers the conversion to be lossless and reversible if the first 15 
significant decimal digits of the number are preserved"


-----Original Message-----
From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On 
Behalf Of Thomas Kurz
Sent: Thursday, April 12, 2018 2:50 PM
To: SQLite mailing list
Subject: Re: [sqlite] To use or not to use single quotes with integers

Dear Simon,

> A similar thing happens when you specify that a column has affinity of REAL.  
> In both cases, SQLite considers that the CREATE command knows better than 
> whatever specifies the value, and does the conversion.  However for the 
> number to be stored the conversion has to be reversible.  If SQLite reverses 
> the conversion and doesn't get the original string back it stores the string 
> instead.

I don't think this is actually the case:

create table test (i integer, r real, s text);
insert into test (i, r, s) values (3.141592653589793238462643, 
3.141592653589793238462643, 3.141592653589793238462643);
insert into test (i, r, s) values ('3.141592653589793238462643', 
'3.141592653589793238462643', '3.141592653589793238462643');
select * from test;

In any case except of actually storing the string to column s, I get the stored 
value truncated to 14 decimals.

select cast(s as text) from test;

Even here, the first value is truncated to 14 decimals. Only the 2nd is correct.

Kind regards,
Thomas

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to