To say of what is that it is not, or of what is not that it is, is false, while to say of what is that it is, and of what is not that it is not, is true. | Aristoteles
Als daar overeenkomsten in zitten zou dat een hint kunnen zijn richting de logica
{signature}
Waarbij het om de andere machine om testdata gaat en veelal herhalende informatie is. Word er bij de machine waar het voorkomt een test gedaan met importeren van daadwerkelijke gegevens. Deze gegevens zijn diverser en daar is de kans op een match dus op kolomnaam schijnbaar groter. Het is een tekst met respectievelijk 9 en 29 karakters lang.
Ik zou graag willen weten wat voor test er wordt uitgevoerd.Voutloos schreef op dinsdag 22 juni 2010 @ 09:13:
Het is idd gewoon een test op de waarde van lastname.
[ Voor 18% gewijzigd door Spiral op 22-06-2010 09:29 . Reden: Reageren op Voutloos ]
To say of what is that it is not, or of what is not that it is, is false, while to say of what is that it is, and of what is not that it is not, is true. | Aristoteles
Edit: het lijkt bij een snelle test alleen te werken met velden die met een 1 beginnen.
1
2
| SELECT "1foo" = true; -- result: 1 SELECT "bar" = true; -- result: 0 |
[ Voor 33% gewijzigd door CodeCaster op 22-06-2010 09:30 ]
https://oneerlijkewoz.nl
Op papier is hij aan het tekenen, maar in de praktijk...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| CREATE TABLE `Test` ( `Prut` varchar(6) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `Test` -- INSERT INTO `Test` (`Prut`) VALUES ('abc'), ('123abc'), ('Theo'), ('Yes'), ('42'), ('-999'); SELECT * FROM `Test` WHERE Prut; |
Geeft '123abc', '42', '-999'.
{signature}
Héél apart.Voutloos schreef op dinsdag 22 juni 2010 @ 09:28:
SQL:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 CREATE TABLE `Test` ( `Prut` varchar(6) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `Test` -- INSERT INTO `Test` (`Prut`) VALUES ('abc'), ('123abc'), ('Theo'), ('Yes'), ('42'), ('-999'); SELECT * FROM `Test` WHERE Prut;
Geeft '123abc', '42', '-999'.
1
| SELECT "-999" = true |
Geeft 0 terug...
https://oneerlijkewoz.nl
Op papier is hij aan het tekenen, maar in de praktijk...
Kan je daaruit concluderen dat de kolomnaam geen invloed heeft op de functie die de where clause evalueert?
To say of what is that it is not, or of what is not that it is, is false, while to say of what is that it is, and of what is not that it is not, is true. | Aristoteles
Zo. En begin nu maar 100 posts over hoe stupide deze mysql feature is, terwijl je het helemaal nooit last van hoeft te hebben.

{signature}
Haha nee zal ik niet gaan doen. Ben al blij dat ik niet de enige ben die de logica erachter niet snapt. Het is gewoon een, tot dusver bekend, niet gedocumenteerde feature van MySQL. Laten we het daar maar bij latenVoutloos schreef op dinsdag 22 juni 2010 @ 09:42:
De kolomnaam zelf maakt inderdaad helemaal niet uit.
Zo. En begin nu maar 100 posts over hoe stupide deze mysql feature is, terwijl je het helemaal nooit last van hoeft te hebben.
To say of what is that it is not, or of what is not that it is, is false, while to say of what is that it is, and of what is not that it is not, is true. | Aristoteles
Dit is gewoon gedocumenteerd hoor, zoals vrijwel alle bugs/features van MySQL:Spiral schreef op dinsdag 22 juni 2010 @ 09:56:
[...]
Haha nee zal ik niet gaan doen. Ben al blij dat ik niet de enige ben die de logica erachter niet snapt. Het is gewoon een, tot dusver bekend, niet gedocumenteerde feature van MySQL. Laten we het daar maar bij laten
http://dev.mysql.com/doc/refman/5.1/en/type-conversion.html
Aan welke criteria voldoet dan de WHERE clause in de documentatie die jij geeft?cariolive23 schreef op dinsdag 22 juni 2010 @ 10:39:
[...]
Dit is gewoon gedocumenteerd hoor, zoals vrijwel alle bugs/features van MySQL:
http://dev.mysql.com/doc/refman/5.1/en/type-conversion.html
Aan de allerlaatste regel zal het dan moeten voldoen, maar waar tegen vergelijkt MySQL het dan? Dat geef je nou net niet op in de WHERE clausule.•If one or both arguments are NULL, the result of the comparison is NULL, except for the NULL-safe <=> equality comparison operator. For NULL <=> NULL, the result is true.
•If both arguments in a comparison operation are strings, they are compared as strings.
•If both arguments are integers, they are compared as integers.
•Hexadecimal values are treated as binary strings if not compared to a number.
•If one of the arguments is a TIMESTAMP or DATETIME column and the other argument is a constant, the constant is converted to a timestamp before the comparison is performed. This is done to be more ODBC-friendly. Note that this is not done for the arguments to IN()! To be safe, always use complete datetime, date, or time strings when doing comparisons. For example, to achieve best results when using BETWEEN with date or time values, use CAST() to explicitly convert the values to the desired data type.
•In all other cases, the arguments are compared as floating-point (real) numbers.
To say of what is that it is not, or of what is not that it is, is false, while to say of what is that it is, and of what is not that it is not, is true. | Aristoteles
Een database heeft een doel namelijk betrouwbaar data opslaan. Logisch gevolg is dat je dit soort zaken niet toestaat. Het is een soort automagische feature. MS SQL en Oracle weigeren gewoon de query.Voutloos schreef op dinsdag 22 juni 2010 @ 09:42:
De kolomnaam zelf maakt inderdaad helemaal niet uit.
Zo. En begin nu maar 100 posts over hoe stupide deze mysql feature is, terwijl je het helemaal nooit last van hoeft te hebben.
In de WHERE is er sprake van booleans, true of false, 1 of 0. MySQL probeert iedere waarde in jouw kolom te kasten naar 1 of 0 en daar komen dus een aantal 1-en uit voort, zie de resultaten. Je kunt dit ook in je SELECT laten zien:Spiral schreef op dinsdag 22 juni 2010 @ 11:07:
[...]
Aan welke criteria voldoet dan de WHERE clause in de documentatie die jij geeft?
[...]
Aan de allerlaatste regel zal het dan moeten voldoen, maar waar tegen vergelijkt MySQL het dan? Dat geef je nou net niet op in de WHERE clausule.
1
2
3
4
5
| SELECT kolom, kolom = true FROM tabel; |
Zo krijg je per waarde te zien of deze wordt gecast naar true of false, 1 of 0.
Ps. PostgreSQL weigert dit soort queries uiteraard ook, een varchar is tenslotte geen boolean. Vrijwel iedere database zal dit weigeren, het is gewoon fout.
[ Voor 9% gewijzigd door cariolive23 op 22-06-2010 12:12 ]
Jij haalt een url aan waar jij aangeeft dat het gedocumenteerd is, maar dat zie ik niet terug in de die url. Voor mij is het duidelijk dat er bij de WHERE clausule een evaluatie plaatsvind.
Ik ben het niet met je eens dat dit gedrag gedocumenteerd is.
[ Voor 70% gewijzigd door Spiral op 22-06-2010 13:06 . Reden: toelichting ]
To say of what is that it is not, or of what is not that it is, is false, while to say of what is that it is, and of what is not that it is not, is true. | Aristoteles
Uit de handleiding:Spiral schreef op dinsdag 22 juni 2010 @ 12:59:
Hoe evalueert de WHERE clausule '-999' dan naar true?
Jij haalt een url aan waar jij aangeeft dat het gedocumenteerd is, maar dat zie ik niet terug in de die url. Voor mij is het duidelijk dat er bij de WHERE clausule een evaluatie plaatsvind.
Ik ben het niet met je eens dat dit gedrag gedocumenteerd is.
-999 is geen 0, dus nonzero, en wordt als boolean dus gecast naar een true.A value of zero is considered false. Nonzero values are considered true
Het staat er echt, ik ben dus van mening dat dit is gedocumenteerd. Dat het extreem vaag gedrag is, dat ben ik ook met je eens, het is niet voor niets dat ik een hekel heb aan MySQL.
•In all other cases, the arguments are compared as floating-point (real) numbers.
1
| SELECT CAST('23test' AS SIGNED) |
Geeft 23
1
| SELECT CAST('test23' AS SIGNED) |
Terwijl deze 0 teruggeeft.
Aangezien 0 gelijk is aan false en alle andere reële waarden gelijkstaan aan true zijn. Zou MySQL alleen de resultaten weergeven waar het begint met een getal ongelijk aan 0 zelf.
Bedankt voor de verdere discussie cariolive23.
To say of what is that it is not, or of what is not that it is, is false, while to say of what is that it is, and of what is not that it is not, is true. | Aristoteles
Dit gedrag maakt MySQL een lastige en kostbare database, het is afhankelijk van jouw data en queries of de zaken toevallig goed of fout gaan. Het resultaat is onvoorspelbaar, met Oracle, SQL Server of PostgreSQL weet je heel zeker dat een string nooit zomaar wordt gecast naar een boolean en krijg je foutmeldingen wanneer je een fout in je SQL maakt. Dat scheelt dus tijd, geld en frustratie.
SQL, NoSQL of NoMySQL? That's the question!