Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generating MD5 idHash directly in MySQL statement

In my table I have an userID that is auto-incremented. In the same row I have an idHash. Is it possible to generate the idHash (simply an MD5 sum) from it directly with the same INSERT statement so that I don't have to SELECT the id, and then UPDATE the idHash again?

Problem is: I do not know the userID before it is being generated (auto-incremented) by MySQL.

Thanks Frank

PS: I'm using PHP. PPS: This question is all about a SINGLE INSERT. I know that I can use PHP or other languages to manually select the data and then update it.

like image 697
Frank Vilea Avatar asked Nov 14 '22 23:11

Frank Vilea


1 Answers

I don't believe you can do it within a single INSERT statement.

What you probably could do is use an INSERT trigger, that both determines the new ID, hashes it, and then updates the record.

like image 85
Alnitak Avatar answered Nov 17 '22 18:11

Alnitak