From: | anand086 <anand086(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Function Code |
Date: | 2017-08-28 23:49:37 |
Message-ID: | 1503964177798-5980522.post@n3.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi All,I need help in writing the a function in PostgresThe function does --•
Generate the 32 hex characters using encode(digest('Welcome123', 'md5'),
'hex').• Then picks up last 16 characters. I used SELECT
SUBSTR(5858ea228cc2edf88721699b2c8638e5, 17, 16) • From these 16 characters,
first 8 characters and second 8 characters are bundled and reversed with in
those 8 characters. • Then reversed characters are concatenated. As an
example, I tried writing the below code but I am stuck and would need help
to write it in correct way --
CREATE OR REPLACE FUNCTION get_code(bytea) returns text AS $$ SELECT
encode(digest($1, 'md5'), 'hex') INTO l_hex_32; SELECT SUBSTR(l_hex_32, 17,
16) INTO l_low_16; SELECT SUBSTR(l_low_16, 1, 8) INTO l_q3; SELECT
SUBSTR(l_low_16, 9, 8) INTO l_q4; SELECT SUBSTR(l_q3, 7, 2)||SUBSTR(l_q3, 5,
2)||SUBSTR(l_q3, 3, 2)||SUBSTR(l_q3, 1, 2) INTO l_q3; SELECT SUBSTR(l_q4,
7, 2)||SUBSTR(l_q4, 5, 2)||SUBSTR(l_q4, 3, 2)||SUBSTR(l_q4, 1, 2) INTO l_q4;
SELECT l_q3||l_q4 into l_low_16_m;$$ LANGUAGE SQL STRICT IMMUTABLE;
In the above code I want to finally return the value of
l_low_16_m.Regards,Anand
--
View this message in context: http://www.postgresql-archive.org/Function-Code-tp5980522.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
From | Date | Subject | |
---|---|---|---|
Next Message | anand086 | 2017-08-28 23:50:04 | Re: Hex to Number conversion |
Previous Message | Andreas Kretschmer | 2017-08-27 07:25:46 | Re: Hex to Number conversion |