This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE OR REPLACE FUNCTION urldecode(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(replace($1, '+', ' '), '%[0-9a-f][0-9a-f]|.', 'gi') AS r(m); | |
| $$ LANGUAGE SQL STRICT; | |
| CREATE OR REPLACE FUNCTION parse_url_query(p varchar) RETURNS json AS $$ | |
| with kv as ( | |
| select urldecode(kv[1]) k, urldecode(kv[2]) v from (select string_to_array(i, '=') kv from unnest(string_to_array(TRIM(BOTH '&' FROM $1), '&')) as s(i)) | |
| ) | |
| select json_object(array(select k from kv), array(select v from kv)); |
OlderNewer