Hi! On Mon, Dec 22, 2008 at 9:09 PM, Jay Pipes <[email protected]> wrote: >> mysql> select cast(c as char(9)) from t; >> +--------------------+ >> | cast(c as char(9)) | >> +--------------------+ >> | 012345678 | >> +--------------------+ >> 1 row in set, 1 warning (0.06 sec) >> >> Warning (Code 1292): Truncated incorrect CHAR(9) value: '0123456789' > > OK, so I still don't see the value of the warning in this case. What value > does it give? If you did the following: > > SELECT CAST(c as CHAR(9)) FROM t; > SELECT LEFT(c, 9) FROM t; > > The first would raise a warning, but the second would not. So, I ask again, > what real value is the warning in this case?
The warning is given because the normal semantics of CAST does not imply information should be lost. So, CAST was executed but had some side effect that is not part of the normal semantics. The semantics of LEFT are simply to take the leftmost characters. It is 'part of the deal' that you may end up with part of the original value - in fact, it is the purpose of LEFT to do just that. That's why you don't get a warning for LEFT. Another example where a warning would be in order. Suppose you create a foreign key on an Innodb table. Creating the foreign key may have the side-effect of creating an index as well. It would make perfect sense in this case to provide a warning to inform the user of the side-effect. > > Currently, we have actually 3 levels: > > ERROR, WARNING, and NOTE. > > I could see the possible value of outputting a NOTE in this case: Well, maybe. THe thing with NOTE is that it's semantics are not really clearly described. According to the standard, executing a statement results in either an exception (statement cannot be executed, nothing happens) or in a completion condition. Completion condition is one of successful completion, no data found or warning: " The completion condition warning is broadly defined as completion in which the effects are correct, but there is reason to caution the user about those effects. It is raised for implementation-defined conditions as well as conditions specified in this part of ISO/IEC 9075. The completion condition no data has special significance and is used to indicate an empty result. The completion condition successful completion is defined to indicate a completion condition that does not correspond to warning or no data. This includes conditions in which the SQLSTATE subclass provides implementation-defined information of a non-cautionary nature. " > > SELECT CAST(c as CHAR(9)) FROM t; > > But not a warning. By doing an explicit CAST(), you are essentially saying > to the server "Yes, I know what I am doing, don't warn me about stuff...". No - I don't agree on this one. CAST means: change the type - it does not imply that the conversion should be lossy. IMO, It is A Good Thing you get a nudge that the conversion was lossy. kind regards, Roland > > -jay > >> Hope this is clear now...I ask the db to cast, it knows how to do it, >> it does it, but it results in data loss -> warning. >> This is in fact standard behaviour in case you're in doubt. >> >> The NULL thing discussed earlier - well, that should have been an >> error according to the standard. Reason: column is defined as NOT >> NULL, so you *cannot* legally store NULL in it without breaking the >> constraint. MySQL in that case does *not* do what we ask from it (we >> asked to store a NULL, but instead it stores the 'datatype default' >> wetf that may be) so that *should* have been an error - not a warning. >> >> I hope this helps. >> >> On Fri, Dec 19, 2008 at 10:12 PM, Sheeri K. Cabral <[email protected]> >> wrote: >>> >>> On 12/19/08, Jay Pipes <[email protected]> wrote: >>>> >>>> FYI, if folks decide we can scrap warnings, I can mentor a community >>>> member in the task of replacing warnings with errors. It's not a >>>> particularly difficult task, basically broken into 4 phases: >>>> >>>> 1) Identify all code locations that emit warnings >>>> 2) Replace with errors >>>> 3) Remove the warnings system entirely >>>> 4) Fix EXPLAIN EXTENDED to not use SHOW WARNINGS afterwards (this was >>>> always a total hack) >>>> >>>> -jay >>> >>> While I agree with the ideas here, I don't think we can actually scrap >>> all >>> warnings without someone going through the warning codes and making sure >>> there's no functionality being lost. There very well may be times where >>> we >>> want an error instead of a warning or having an error and a warning for >>> two >>> similar issues that are different in severity. No, I can't think of >>> anything concrete right now. >>> >>> -Sheeri >>> >>> _______________________________________________ >>> Mailing list: https://launchpad.net/~drizzle-discuss >>> Post to : [email protected] >>> Unsubscribe : https://launchpad.net/~drizzle-discuss >>> More help : https://help.launchpad.net/ListHelp >>> >>> >> >> >> > > -- Roland Bouman http://rpbouman.blogspot.com/ _______________________________________________ Mailing list: https://launchpad.net/~drizzle-discuss Post to : [email protected] Unsubscribe : https://launchpad.net/~drizzle-discuss More help : https://help.launchpad.net/ListHelp

