agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: anand086 <anand086@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Function Code
Date: Mon, 28 Aug 2017 16:49:37 -0700 (MST)
Message-ID: <1503964177798-5980522.post@n3.nabble.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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.
view thread (2+ messages) latest in thread
Message-ID: <1503964177798-5980522.post@n3.nabble.com>
Permalink: ../1503964177798-5980522.post@n3.nabble.com/
Also on: postgresql.org/message-id/1503964177798-5980522.post@n3.nabble.com
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: anand086@gmail.com
Subject: Re: Function Code
In-Reply-To: <1503964177798-5980522.post@n3.nabble.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox