pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feed From: MichaelDBA <MichaelDBA@sqlexec.com>
To: JORGE MALDONADO <jorgemal1960@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: URL Decode function
Date: Tue, 6 Apr 2021 08:56:10 -0400
Message-ID: <ed9bfcd4-f052-5ccd-5304-b70f8643a171@sqlexec.com> (raw )
In-Reply-To: <CAAY=A79T+2DtCt6pv2AKAnP2Azsb6MPLJxZSV0C3GS=AvjOq9g@mail.gmail.com >
References: <CAAY=A79T+2DtCt6pv2AKAnP2Azsb6MPLJxZSV0C3GS=AvjOq9g@mail.gmail.com >
Hi,
You can create your own "decode" function in pg like this example using
varchars as input. Then simply create other overloaded "decode"
functions for different input datatypes.
CREATE OR REPLACE FUNCTION decode(expr varchar, search varchar, result varchar, dflt varchar) RETURNS varchar AS
$$
BEGIN
CASE WHEN expr = search THEN RETURN result; ELSE RETURN dflt; END CASE;
END
$$ LANGUAGE plpgsql;
Regards,
Michael Vitale
JORGE MALDONADO wrote on 4/6/2021 12:34 AM:
> Hi,
>
> In my DB, one of my tables has a field that is URL Encoded (its value
> is a URL of course).
>
> For example, the value:
> *https://www.cosmohits.com/ListasPopularidad/ListaPopularidad/1-la-superlista*
> is URL Encoded like this:
> *https%3A%2F%2Fwww.cosmohits.com
> <http://2Fwww.cosmohits.com>%2FListasPopularidad%2FListaPopularidad%2F1-la-superlista
> *
>
> Is there a PostgreSQL function to URL Decode such field when
> performing a SELECT statement? I have not found anything in documentation.
>
> Best regards,
> Jorge Maldonado
>
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&... ;
> Virus-free. www.avast.com
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&... ;
>
>
view thread (4+ messages) latest in thread
Message-ID: <ed9bfcd4-f052-5ccd-5304-b70f8643a171@sqlexec.com>
Permalink: ../ed9bfcd4-f052-5ccd-5304-b70f8643a171@sqlexec.com/
Also on: postgresql.org/message-id/ed9bfcd4-f052-5ccd-5304-b70f8643a171@sqlexec.com
copy link · copy postgr.es
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: MichaelDBA@sqlexec.com, jorgemal1960@gmail.com
Subject: Re: URL Decode function
In-Reply-To: <ed9bfcd4-f052-5ccd-5304-b70f8643a171@sqlexec.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox