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:
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 :)
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
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
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
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
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
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
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
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
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
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
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,
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?
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
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
> 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
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)
18 matches
Mail list logo