0

the following query is not working in MYSql (a Trigger)

set new.uniq = SUBSTR(md5(concat(new.lat, '-', new.lon)),0,5)

only if i delete the SUBSTR it will give me an correct output

set new.uniq = md5(concat(new.lat, '-', new.lon))
2
  • Please, can you put what new.uniq, new.lat and new.lon do? Commented May 31, 2015 at 0:33
  • If you want the leftmost characters, you can use the LEFT function instead of SUBSTR. For example, if you want the leftmost five characters LEFT(expr,5) Commented May 31, 2015 at 1:05

1 Answer 1

1

The problem is the zero:

set new.uniq = SUBSTR(md5(concat(new.lat, '-', new.lon)),0,5)
                                                         ^

For example:

SELECT SUBSTR('whatever', 0, 5) --> returns empty string
SELECT SUBSTR('whatever', 1, 5) --> returns 'whate'

Change the zero to a 1 and you should be fine:

set new.uniq = SUBSTR(md5(concat(new.lat, '-', new.lon)),1,5)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.