1

I have a value 8122 which has a trailing space at the end. Why does my sql script isn't catching this? This is the sql script:

select * from values where value like '% ' or value like ' %';

How to set the LIKE to be more sensitive in this sense?

Vladimir Despotovic
  • 3,200
  • 2
  • 30
  • 58

1 Answers1

1

Check the length of the tsrngsm before and after trimming

values is a reserved word in mysql

SELECT 
    * 
FROM `values `
WHERE LENGTH(value) > LENGTH(TRIM(value));

If you only want to oheck right spaces you use RTRIM and for left LTRIM

Incase you are looking for only one space you must check

SELECT 
    * 
FROM `values `
WHERE LENGTH(value)-1 = LENGTH(RTRIM(value))
    OR LENGTH(value)-1 = LENGTH(LTRIM(value));
nbk
  • 45,398
  • 8
  • 30
  • 47
  • I tried select * from test where LENGTH(value) < LENGTH(TRIM(value)); and it is not catching it actually.......so very weird.... – Vladimir Despotovic Jun 26 '20 at 12:27
  • 1
    you have to switch from > to < the triommed is smaller than the original sorry – nbk Jun 26 '20 at 12:29
  • 1
    It should work but doesn't do it all the times https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=daa9bead30611f6bbbd495c2fe2aac11 – nbk Jun 26 '20 at 12:48
  • God damn it, looks iek it depends on the mysql version. I cannot believe there is no way to detect this!!!!!! It is idiotic that they didn't put this distinction in......purely idiotic – Vladimir Despotovic Jun 26 '20 at 12:50
  • i believe it is a bug so i reported it https://bugs.mysql.com/bug.php?id=100008 – nbk Jun 26 '20 at 13:10