pramsey/pgsql-http

Want to change the parameters to accommodate the wider needs.

lvbuwei opened this issue · 2 comments

current:

CREATE OR REPLACE FUNCTION urlencode(string VARCHAR)
    RETURNS TEXT
    AS 'MODULE_PATHNAME'
    LANGUAGE 'c'
    IMMUTABLE STRICT;

if change to:

CREATE OR REPLACE FUNCTION urlencode(string bytea)
    RETURNS TEXT
    AS 'MODULE_PATHNAME'
    LANGUAGE 'c'
    IMMUTABLE STRICT;

Because I recently had a requirement that needs to encode the gbk character set

select urlencode('123中中');
       urlencode       
-----------------------
 123%E4%B8%AD%E4%B8%AD

IS OK.

select urlencode(convert_to('123中中','gbk'));

EXCEPTION


select urlencode(convert_to('123中中','gbk')::text);
urlencode

%5Cx313233d6d0d6d0

IS ERROR.

change string VARCHAR to string bytea

select urlencode(convert_to('123中中','gbk'));
┌─────────────────┐
│ urlencode │
├─────────────────┤
│ 123%D6%D0%D6%D0 │
└─────────────────┘
(1 row)

IS OK.

Please forgive me for my poor English

OR

append http.sql
add line

CREATE OR REPLACE FUNCTION urlencode(string bytea)
RETURNS TEXT
AS 'MODULE_PATHNAME'
LANGUAGE 'c'
IMMUTABLE STRICT;

also ok.

I'm not sure why you are pushing your wide text through bytea? PgSQL supports lots of text encodings, why not work with text?