Priidu Neemre
Priidu Neemre

Reputation: 3061

URL-encoding VARCHAR and TEXT values in PostgreSQL

Are there any well-known PL functions/libraries for extending a PostgreSQL (9.4.1) database with URL encoding (also known as percent encoding) capabilities?

Here's an example of the intended functionality:

I guess an alternative would be to roll out my own implementation, since AFAIK there is currently no built-in way of doing this.

Upvotes: 0

Views: 3909

Answers (1)

Craig Ringer
Craig Ringer

Reputation: 324771

This is trivial to do in an external PL,e.g.

CREATE LANGUAGE plpythonu;

CREATE OR REPLACE FUNCTION urlescape(original text) RETURNS text LANGUAGE plpythonu AS $$
import urllib
return urllib.quote(original);
$$
IMMUTABLE STRICT;

Upvotes: 3

Related Questions