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?

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.

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

Reply via email to