Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lTlMO-0007c8-8k for pgsql-sql@arkaria.postgresql.org; Tue, 06 Apr 2021 13:03:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lTlMN-0005iK-6D for pgsql-sql@arkaria.postgresql.org; Tue, 06 Apr 2021 13:03:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lTlMM-0005iD-K3 for pgsql-sql@lists.postgresql.org; Tue, 06 Apr 2021 13:03:10 +0000 Received: from post.visena.com ([46.226.10.50]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.92) (envelope-from ) id 1lTlMJ-0007Bb-7m for pgsql-sql@postgresql.org; Tue, 06 Apr 2021 13:03:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=visena.com; s=20141101.wh; h=Content-Type:MIME-Version:Subject:References:In-Reply-To:Message-ID:Cc:To:From:Date; bh=OuCIjAIojBHBUj5n7BhehZkzI05+6dPB3A5iOztAkmM=; b=FH7ybLy0nh5xUy9/jsIUPot/+LUZFV63o5dynKGAoEnV7izjYvJYDTa3SuQ/ykdeEzoZAtbOSAI6VCAkvxXOxkbP41+CkfTRMUwJBGfpQconG7y4lTjCAze9RLynwqWRSKI3mNvj/M8chVqdqrIh4nNLSpQWyePWq9k++ceTCEo=; Received: from tc7-visena.wh.internal.visena.com ([10.0.1.10]) by post.visena.com with esmtp (Exim 4.82) (envelope-from ) id 1lTlMF-0005qx-6y; Tue, 06 Apr 2021 15:03:03 +0200 Received: from localhost ([127.0.0.1] helo=tc7-visena.wh.internal.visena.com) by tc7-visena.wh.internal.visena.com with esmtp (Exim 4.90_1) (envelope-from ) id 1lTlMF-0001HZ-3L; Tue, 06 Apr 2021 15:03:03 +0200 Date: Tue, 6 Apr 2021 15:03:02 +0200 (CEST) From: Andreas Joseph Krogh To: MichaelDBA Cc: JORGE MALDONADO , pgsql-sql@postgresql.org Message-ID: In-Reply-To: References: Subject: Re: URL Decode function MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_232_1977742188.1617714182870" X-Mailer: Visena Mail 2.2.612 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------=_Part_232_1977742188.1617714182870 Content-Type: multipart/related; boundary="----=_Part_233_1163974158.1617714182870" ------=_Part_233_1163974158.1617714182870 Content-Type: multipart/alternative; boundary="----=_Part_234_1145714330.1617714182990" ------=_Part_234_1145714330.1617714182990 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable P=C3=A5 tirsdag 06. april 2021 kl. 14:56:10, skrev MichaelDBA < MichaelDBA@sqlexec.com >: Hi, You can create your own "decode" function in pg like this example using=20 varchars as input. Then simply create other overloaded "decode" functions f= or=20 different input datatypes. CREATE OR REPLACE FUNCTION decode(expr varchar, search varchar, result=20 varchar, dflt varchar) RETURNS varchar AS $$ BEGIN CASE WHEN expr =3D searc= h THEN=20 RETURN result; ELSE RETURN dflt; END CASE; END $$ LANGUAGE plpgsql;=20 Am I the only one who cannot find anything related to the OP's question in= =20 this answer?=20 I found this on SO:=20 CREATE OR REPLACE FUNCTION decode_url_part(p varchar) RETURNS varchar AS $$= =20 SELECT convert_from(CAST(E'\\x' || string_agg(CASE WHEN length(r.m[1]) =3D = 1 THEN=20 encode(convert_to(r.m[1], 'SQL_ASCII'), 'hex') ELSE substring(r.m[1] from 2= for=20 2) END, '') AS bytea), 'UTF8') FROM regexp_matches($1, '%[0-9a-f][0-9a-f]|.= ',=20 'gi') AS r(m); $$ LANGUAGE SQL IMMUTABLE STRICT;=20 andreak@[local]:5432 13.2 test=3D# select=20 decode_url_part('https%3A%2F%2Fwww.cosmohits.com%2FListasPopularidad%2FList= aPopularidad%2F1-la-superlista'); =20 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 =E2=94=82 decode_url_part =E2=94=82 =20 =E2=94=9C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=A4 =E2=94=82=20 https://www.cosmohits.com/ListasPopularidad/ListaPopularidad/1-la-superlist= a =E2=94=82 =20 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 (1 row) -- Andreas Joseph Krogh=20 ------=_Part_234_1145714330.1617714182990 Content-Type: text/html;charset=UTF-8 Content-Transfer-Encoding: quoted-printable
P=C3=A5 tirsdag 06. april 2021 kl. 14:56:10, skrev MichaelDBA <MichaelDBA@sqlexec.com>:
Hi,

You can create your own "decode" function in pg like this example= using varchars as input.=C2=A0 Then simply create other overloaded "d= ecode" functions for different input datatypes.
=C2=A0
CREATE OR REPLACE FUNCTION decode(expr varchar, search varchar, result varc=
har, dflt varchar) RETURNS varchar AS
$$     =20
BEGIN
CASE WHEN expr =3D search THEN RETURN result; ELSE RETURN dflt; END CASE;
END
$$ LANGUAGE plpgsql;
=C2=A0
Am I the only one who cannot find anything related to the OP's questio= n in this answer?
">
=C2=A0
I found this on SO:
=C2=A0
CREATE OR REP=
LACE FUN=
CTION decode_url_part(p varchar) RETURNS varchar AS $$
SELECT convert_from(CAST(E'\\x' || =
string_agg(CASE WHEN length(r.m[1]) =3D 1<=
/span> T=
HEN encode(convert_to(r.m[1], 'SQL_ASCII'), 'hex') ELSE substring(r.m[<=
span class=3D"hljs-number" style=3D"margin: 0px; padding: 0px; border: 0px;=
 font-style: inherit; font-variant: inherit; font-weight: inherit; font-str=
etch: inherit; line-height: inherit; font-family: inherit; vertical-align: =
baseline; box-sizing: inherit; color: var(--highlight-namespace);">1=
] from 2=
 =
for 2) END, '') AS bytea), 'UTF8')
FROM regexp_matches($1, '%[0-9a-f][0-9a-f]|.', 'gi') AS r(m);
$$ LANGU=
AGE SQL IMMUTABLE STRICT;
=C2=A0
andreak@[local]:5432 = 13.2 test=3D# select decode_url_part('https%3A%2F%2Fwww.co= smohits.com%2FListasPopularidad%2FListaPopularidad%2F1-la-superlista');
=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90
=E2=94=82 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0decode_url_part =C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=E2=94=82
=E2=94=9C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=A4
=E2=94=82 https://www.cosmohits.com/ListasPopularidad/ListaPopularidad/1-la= -superlista =E2=94=82
=E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98
(1 row)

=C2=A0
--
Andreas Joseph Krogh
------=_Part_234_1145714330.1617714182990-- ------=_Part_233_1163974158.1617714182870-- ------=_Part_232_1977742188.1617714182870--