Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dmTnx-0000Ex-8S for pgsql-sql@arkaria.postgresql.org; Mon, 28 Aug 2017 23:50:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dmTnv-0003NN-Vq for pgsql-sql@arkaria.postgresql.org; Mon, 28 Aug 2017 23:50:52 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dmTmt-0000Oy-CI for pgsql-sql@postgresql.org; Mon, 28 Aug 2017 23:49:47 +0000 Received: from n3.nabble.com ([162.255.23.22]) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dmTmm-00040w-0k for pgsql-sql@postgresql.org; Mon, 28 Aug 2017 23:49:46 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id CDDD281BB0A4 for ; Mon, 28 Aug 2017 16:49:37 -0700 (MST) Date: Mon, 28 Aug 2017 16:49:37 -0700 (MST) From: anand086 To: pgsql-sql@postgresql.org Message-ID: <1503964177798-5980522.post@n3.nabble.com> Subject: Function Code MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_116386_1935765555.1503964177798" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org ------=_Part_116386_1935765555.1503964177798 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi All,I need help in writing the a function in PostgresThe function does -= -=E2=80=A2 Generate the 32 hex characters using encode(digest('Welcome123', 'md5'), 'hex').=E2=80=A2 Then picks up last 16 characters. I used SELECT SUBSTR(5858ea228cc2edf88721699b2c8638e5, 17, 16) =E2=80=A2 From these 16 ch= aracters, first 8 characters and second 8 characters are bundled and reversed with in those 8 characters. =E2=80=A2 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 $$=09SELECT encode(digest($1, 'md5'), 'hex') INTO l_hex_32;=09SELECT SUBSTR(l_hex_32, 1= 7, 16) INTO l_low_16;=09SELECT SUBSTR(l_low_16, 1, 8) INTO l_q3;=09SELECT SUBSTR(l_low_16, 9, 8) INTO l_q4;=09SELECT 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= ; =20 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=20 l_low_16_m.Regards,Anand -- View this message in context: http://www.postgresql-archive.org/Function-Co= de-tp5980522.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. ------=_Part_116386_1935765555.1503964177798 Content-Type: text/html; charset=UTF8 Content-Transfer-Encoding: quoted-printable Hi All, I need help in writing the a function in Postgres The function does -- =E2=80=A2 Generate the 32 hex characters using encode(digest('Welcome123', = 'md5'), 'hex'). =E2=80=A2 Then picks up last 16 characters. I used SELECT SUBSTR(5858ea228c= c2edf88721699b2c8638e5, 17, 16)=20 =E2=80=A2 From these 16 characters, first 8 characters and second 8 charact= ers are bundled and reversed with in those 8 characters.=20 =E2=80=A2 Then reversed characters are concatenated.=20 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)=20
returns text AS=20
$$
=09SELECT encode(digest($1, 'md5'), 'hex') INTO l_hex_32;
=09SELECT SUBSTR(l_hex_32, 17, 16) INTO l_low_16;
=09SELECT SUBSTR(l_low_16, 1, 8) INTO l_q3;
=09SELECT SUBSTR(l_low_16, 9, 8) INTO l_q4;
=09SELECT SUBSTR(l_q3, 7, 2)||SUBSTR(l_q3, 5, 2)||SUBSTR(l_q3, 3, 2)||SUBST=
R(l_q3, 1, 2) INTO l_q3;
    SELECT SUBSTR(l_q4, 7, 2)||SUBSTR(l_q4, 5, 2)||SUBSTR(l_q4, 3, 2)||SUBS=
TR(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 =09 =09 =09

View this message in context: Function Code
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
------=_Part_116386_1935765555.1503964177798--