Re: URL Decode function

From: MichaelDBA <MichaelDBA(at)sqlexec(dot)com>
To: Andreas Joseph Krogh <andreas(at)visena(dot)com>
Cc: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: URL Decode function
Date: 2021-04-06 13:07:03
Message-ID: 13235391-a48a-e855-4782-c24864af582e@sqlexec.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

ha, funny.  I thought he was looking for something that acts like the
oracle decode function.  Now that I reread it, it is really talking
about endcoding/decoding stuff.
my bad

Regards,
Michael Vitale

Andreas Joseph Krogh wrote on 4/6/2021 9:03 AM:
> På tirsdag 06. april 2021 kl. 14:56:10, skrev MichaelDBA
> <MichaelDBA(at)sqlexec(dot)com <mailto:MichaelDBA(at)sqlexec(dot)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;
>
> Am I the only one who cannot find anything related to the OP's
> question in this answer?
> I found this on SO:
> |CREATE OR REPLACE FUNCTION decode_url_part(p varchar) RETURNS varchar
> AS $$ SELECT convert_from(CAST(E'\\x' || string_agg(CASE WHEN
> length(r.m[1]) = 1 THEN encode(convert_to(r.m[1], 'SQL_ASCII'), 'hex')
> ELSE substring(r.m[1] from 2 for 2) END, '') AS bytea), 'UTF8') FROM
> regexp_matches($1, '%[0-9a-f][0-9a-f]|.', 'gi') AS r(m); $$ LANGUAGE
> SQL IMMUTABLE STRICT; |
> andreak(at)[local]:543213.2 test=# select
> decode_url_part('https%3A%2F%2Fwww.cosmohits.com%2FListasPopularidad%2FListaPopularidad%2F1-la-superlista');
>
> ┌──────────────────────────────────────────────────────────────────────────────┐
> │                               decode_url_part
>                                │
> ├──────────────────────────────────────────────────────────────────────────────┤
> │
> https://www.cosmohits.com/ListasPopularidad/ListaPopularidad/1-la-superlista
> │
> └──────────────────────────────────────────────────────────────────────────────┘
> (1 row)
> --
> Andreas Joseph Krogh

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message aditya desai 2021-04-19 13:21:53 Substitute of TRY and CATCH in postgres
Previous Message Andreas Joseph Krogh 2021-04-06 13:03:02 Re: URL Decode function