I have modified and re-arranged the SQL statement as below:

insert into EmailSubscription (
    EMAIL,
    ISSUBSCRIBED,
    DATESUBSCRIBED,
    SUBCODE
) 
values (
    '[email protected]',
    true,
    current_timestamp(),
    rawtohex(hash('SHA256', stringtoutf8(concat('[email protected]', 
current_timestamp())), 1))
);

It works with the modification but the outcome when I select the SubCode is 
now shown below:

[email protected] TRUE 2017-08-19 15:12:18.156 *null* 
0032006600660033006600360030006600630061003300610035003100350064003000380065003800320061006500620039006300340039003200350037003500390039003400640064003700320063003700390061003300640061003600380031006400370035003100610062003000310034006100390062003600610061

What I am expecting is the concat as the input for the hash which is 
'[email protected] 15:12:18.156' and after hashing it should be 
'2ff3f60fca3a515d08e82aeb9c492575994dd72c79a3da681d751ab014a9b6aa'. 

How do I format my result to get the hash as shown above ?

On Saturday, August 19, 2017 at 1:47:01 PM UTC+8, Noel Grandin wrote:
>
> something like this:
>
> insert into EmailSubscription (
>     Email,
>     IsSubscribed,
>     DateSubscribed,
>     SubCode
> ) 
> values (
>     "[email protected] <javascript:>",
>     true,
>     current_timestamp(),
>     rawtohex(hash('SHA256', concat("[email protected] <javascript:>", 
> current_timestamp()), 1))
> );
>
>
> On 19 August 2017 at 07:15, Thotheolh <[email protected] <javascript:>> 
> wrote:
>
>> Hi,
>>
>> I am trying to run nested CALL functions but could not get it to work. 
>> Below is my SQL statement.
>>
>> insert into EmailSubscription (
>>>     Email,
>>>     IsSubscribed,
>>>     DateSubscribed,
>>>     SubCode
>>> ) 
>>> values (
>>>     "[email protected] <javascript:>",
>>>     true,
>>>     current_timestamp(),
>>>     call rawtohex(call hash('SHA256', call concat(Email, 
>>> DateSubscribed), 1))
>>> );
>>
>>
>> I want to SHA256 hash the concatenation of the email address with the 
>> timestamp of subscription and then convert the raw SHA256 binary output 
>> into a hexadecimal representation to be inserted as the 'SubCode' for the 
>> table.
>>
>> How should I go about doing that in SQL ?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "H2 Database" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/h2-database.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to