Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6929125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:16:39+00:00 2026-05-27T11:16:39+00:00

I have a column url encoded with urlencode in php. I wish to make

  • 0

I have a column url encoded with urlencode in php. I wish to make a select like this
SELECT some_mix_of_functions(…) AS Decoded FROM table

Replace is not a good solution because I will have to add all the decoding by hand. Any other solution to get the desire result ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:16:40+00:00Added an answer on May 27, 2026 at 11:16 am

    Yes you can:

    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;
    

    This creates a function decode_url_part, then you can use it like that:

    SELECT decode_url_part('your%20urlencoded%20string')
    

    Or you can just use the mix of functions and subqueries from the body of the above function.

    This doesn’t handle ‘+’ characters (representing whitespace), but I guess adding this is quite easy (if you ever need it).

    Also, this assumes utf-8 encoding for non-ascii characters, but you can replace ‘UTF8’ with your own encoding if you want.

    It should be noted that the above code relies on undocumented postgresql feature, namely that the results of regexp_matches function are processed in the order they occur in the original string (which is natural, but not specified in docs).

    As Pablo Santa Cruz notes, string_agg is a PostgreSQL 9.0 aggregate function. The equivalent code below doesn’t use it (I hope it works for 8.x):

    SELECT convert_from(CAST(E'\\x' || array_to_string(ARRAY(
        SELECT 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
        FROM regexp_matches($1, '%[0-9a-f][0-9a-f]|.', 'gi') AS r(m)
    ), '') AS bytea), 'UTF8');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have table with column 'URL' whrere I store urls like this
I need a select from table which does not have column that tells when
I have a column with a url sting that looks like this http://www.somedomain.edu/rootsite1/something/something/ or
I have column that contains strings. The strings in that column look like this:
I have a database with VARCHAR column url . I would like to fetch
Suppose I have an entries under a column 'URL' like so: URL GET /books/fiction?id=324223
I have a php page that returns json like this: while ($row = oci_fetch_array($stid,
I have a DB table with one of the column as URL have row
I have a column 'date' in my DataSet. I would like to filter this
I have column with varchar values like 022008 that I need to convert into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.