Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-07 Thread David Raymond
sqlite> insert into weights values (null); Error: CHECK constraint failed: float How about ...check (cast(float as real) = float)... ? sqlite> insert into weights values (1); sqlite> insert into weights values (0); sqlite> insert into weights values ('Hello'); Error: CHECK constraint failed:

Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread R Smith
On 2017/09/07 12:35 AM, Cecil Westerhof wrote: ​It does not, but this does: CREATE TABLE weights( float REAL, CONSTRAINT float CHECK(TYPEOF(float) IN ("real","integer")) ); Instead of "int" you need "integer". yes of course... My bad, sorry, but at least you've solved it :)

Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread Cecil Westerhof
2017-09-07 0:57 GMT+02:00 Simon Slavin : > > > On 6 Sep 2017, at 11:31pm, Cecil Westerhof wrote: > > > 2017-09-07 0:20 GMT+02:00 Richard Hipp : > > > >> On 9/6/17, Cecil Westerhof wrote: > >> > >>> Maybe this

Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread Cecil Westerhof
2017-09-07 0:36 GMT+02:00 Wolfgang Enzinger : > Am Thu, 7 Sep 2017 00:28:56 +0200 schrieb Cecil Westerhof: > > > 2017-09-07 0:20 GMT+02:00 Wolfgang Enzinger : > > >> Add this trigger and everything is fine. ;-) > >> > >> CREATE TRIGGER

Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread Simon Slavin
On 6 Sep 2017, at 11:31pm, Cecil Westerhof wrote: > 2017-09-07 0:20 GMT+02:00 Richard Hipp : > >> On 9/6/17, Cecil Westerhof wrote: >> >>> Maybe this is correct, but it is certainly confusing. >> >> The constraint check

Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread Wolfgang Enzinger
Am Thu, 7 Sep 2017 00:28:56 +0200 schrieb Cecil Westerhof: > 2017-09-07 0:20 GMT+02:00 Wolfgang Enzinger : >> Add this trigger and everything is fine. ;-) >> >> CREATE TRIGGER weights_float_force_datatype >> BEFORE INSERT ON weights >> FOR EACH ROW >> BEGIN >> INSERT INTO

Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread Cecil Westerhof
2017-09-07 0:05 GMT+02:00 R Smith : > On 2017/09/06 11:58 PM, R Smith wrote: > >> Your CHECK constraint should really find that the value is acceptable >> when it is either a REAL, OR an INT, because both those types of data >> satisfies your requirement. >> >> > To be

Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread Cecil Westerhof
2017-09-07 0:20 GMT+02:00 Richard Hipp : > On 9/6/17, Cecil Westerhof wrote: > > > > Maybe this is correct, but it is certainly confusing. > > > > The constraint check occurs before the implicit conversion. > ​Should that not be the other way around? But

Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread Cecil Westerhof
2017-09-07 0:20 GMT+02:00 Wolfgang Enzinger : > Am Thu, 7 Sep 2017 00:15:39 +0200 schrieb Cecil Westerhof: > > > 2017-09-07 0:05 GMT+02:00 R Smith : > > > >> On 2017/09/06 11:58 PM, R Smith wrote: > >> > >>> Your CHECK constraint should really find that

Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread Wolfgang Enzinger
Am Thu, 7 Sep 2017 00:15:39 +0200 schrieb Cecil Westerhof: > 2017-09-07 0:05 GMT+02:00 R Smith : > >> On 2017/09/06 11:58 PM, R Smith wrote: >> >>> Your CHECK constraint should really find that the value is acceptable >>> when it is either a REAL, OR an INT, because both

Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread Richard Hipp
On 9/6/17, Cecil Westerhof wrote: > > Maybe this is correct, but it is certainly confusing. > The constraint check occurs before the implicit conversion. -- D. Richard Hipp d...@sqlite.org ___ sqlite-users mailing list

Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread Cecil Westerhof
2017-09-07 0:05 GMT+02:00 R Smith : > On 2017/09/06 11:58 PM, R Smith wrote: > >> Your CHECK constraint should really find that the value is acceptable >> when it is either a REAL, OR an INT, because both those types of data >> satisfies your requirement. >> >> > To be

Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread R Smith
On 2017/09/06 11:58 PM, R Smith wrote: Your CHECK constraint should really find that the value is acceptable when it is either a REAL, OR an INT, because both those types of data satisfies your requirement. To be specific, this should work for you: CREATE TABLE weights( float REAL,

Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread Cecil Westerhof
2017-09-06 23:58 GMT+02:00 R Smith : > On 2017/09/06 11:37 PM, Cecil Westerhof wrote: > >> But should in the first case the 0 not be cast to a 0.0? >> > > What makes you believe SQLite should massage the data into specific types > for you without you requesting it explicitly?

Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread R Smith
On 2017/09/06 11:37 PM, Cecil Westerhof wrote: But should in the first case the 0 not be cast to a 0.0? What makes you believe SQLite should massage the data into specific types for you without you requesting it explicitly? In fact, that would consume valuable extra CPU cycles and would

Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread Cecil Westerhof
2017-09-06 23:49 GMT+02:00 Jens Alfke : > > > > On Sep 6, 2017, at 2:37 PM, Cecil Westerhof > wrote: > > > > But should in the first case the 0 not be cast to a 0.0? > > No, SQLite ignores column type declarations. There's a whole article on > the

Re: [sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread Jens Alfke
> On Sep 6, 2017, at 2:37 PM, Cecil Westerhof wrote: > > But should in the first case the 0 not be cast to a 0.0? No, SQLite ignores column type declarations. There's a whole article on the website on SQLite's dynamic approach to data typing. —Jens

[sqlite] Should the INTEGER not be cast to a REAL

2017-09-06 Thread Cecil Westerhof
I defined the following table: CREATE TABLE weights( float REAL, CONSTRAINT float CHECK(TYPEOF(float) = "real") ); I try the following insert: INSERT INTO testing (float) VALUES (0) But this gives: CHECK constraint failed: float When I try this insert: INSERT INTO testing (float)