2017-09-07 0:20 GMT+02:00 Wolfgang Enzinger <sql...@enzinger.net>:

> Am Thu, 7 Sep 2017 00:15:39 +0200 schrieb Cecil Westerhof:
>
> > 2017-09-07 0:05 GMT+02:00 R Smith <rsm...@rsweb.co.za>:
> >
> >> 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,
> >>     CONSTRAINT float CHECK(TYPEOF(float) IN ("real","int"))
> >> );
> >
> >
> > ​But it does not.
> >
> > The strange thing is: when I remove the constraint and do:
> > INSERT INTO testing
> > (float)
> > VALUES
> > (0)
> >
> > The insert is successful of-course.
> > When I then execute:
> > SELECT float, TYPEOF(float)
> > FROM testing
> >
> > I get:
> > "0.0"    "real"
> >
> >
> > Maybe this is correct, but it is certainly confusing.
>
> Add this trigger and everything is fine. ;-)
>
> CREATE TRIGGER weights_float_force_datatype
> BEFORE INSERT ON weights
> FOR EACH ROW
> BEGIN
> INSERT INTO weights(float) VALUES (CAST (new.float AS REAL));
> SELECT RAISE(IGNORE);
> END
>

​I do not think I should do that.
Executing:
SELECT CAST("Hello" AS REAL), TYPEOF(CAST("Hello" AS REAL))

Gives:
"0.0"    "real"

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

Reply via email to