MySQL SHA256 with Insert Statement
29,976
You can insert a SELECT
instead of VALUES
to run a function on one of the inputs:
INSERT INTO `loop`.`User`
(`userID`,
`firstName`,
`lastName`,
`email`,
`password`,
`userName`,
`bio`,
`spamCount`)
SELECT
'gZvTtlPtjGRqeMBaLji3HxoKB5EZCsNL',
'Joe',
'Smith',
'[email protected]',
SHA2('testgZvTtlPtjGRqeMBaLji3HxoKB5EZCsNL', 256),
'[email protected]',
"TEST BIO",
0;
Author by
John Down
Updated on November 11, 2021Comments
-
John Down over 2 years
I want to create a script to fill a database for testing. How would I set a string to be hashed and the inserted into the database?
I have:
INSERT INTO `loop`.`User` (`userID`, `firstName`, `lastName`, `email`, `password`, `userName`, `bio`, `spamCount`) VALUES ('gZvTtlPtjGRqeMBaLji3HxoKB5EZCsNL', 'Joe', 'Smith', '[email protected]', SHA2('testgZvTtlPtjGRqeMBaLji3HxoKB5EZCsNL', 256), '[email protected]', "TEST BIO", 0);
How do I hash the string and INSERT in same statement?