2017-09-07 0:36 GMT+02:00 Wolfgang Enzinger <sql...@enzinger.net>: > Am Thu, 7 Sep 2017 00:28:56 +0200 schrieb Cecil Westerhof: > > > 2017-09-07 0:20 GMT+02:00 Wolfgang Enzinger <sql...@enzinger.net>: > > >> 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" > > Depends. ;-) What else do you think CAST("Hello" AS REAL) should be > converted to? >
I think the cast itself is not wrong, but if I would use the mentioned trigger then "Hello" would be inserted as 0.0 instead of generating an exception. > Seriously: in case you cannot be sure that only numbers will be inserted > into this column you should probably expand the trigger with a CASE WHEN > ... ELSE ... END construct. > It seems that: CONSTRAINT float CHECK(TYPEOF(float) IN ("real","integer")) is doing what I want. -- Cecil Westerhof _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users