仅具有内置功能的urlencode [英] urlencode with only built-in functions

查看:118
本文介绍了仅具有内置功能的urlencode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在不使用plpgsql的情况下,我试图在pgsql SELECT语句中对给定文本进行urlencode.

Without using plpgsql, I'm trying to urlencode a given text within a pgsql SELECT statement.

此方法的问题:

select regexp_replace('héllo there','([^A-Za-z0-9])','%' || encode(E'\\1','hex'),'g')

...是编码函数未传递regexp参数,除非存在另一种从替换表达式内部调用函数的方法,该方法实际上是有效的.因此,我想知道是否存在一个替换表达式,该表达式本身可以将匹配项编码为十六进制值.

...is that the encode function is not passed the regexp parameter, unless there's another way to call functions from within the replacement expression that actually works. So I'm wondering if there's a replacement expression that, by itself, can encode matches into hex values.

可能还有其他功能组合.我以为那里会有一个聪明的正则表达式(也许仍然是答案),但是我很难找到它.

There may be other combinations of functions. I thought there would be a clever regex (and that may still be the answer) out there, but I'm having trouble finding it.

推荐答案

select regexp_replace(encode('héllo there','hex'),'(..)',E'%\\1','g');

但这不会使字母数字字符易于理解.

This doesn't leave the alphanumeric characters human-readable, though.

这篇关于仅具有内置功能的urlencode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆