postgresql支持在正则表达式后面吗? [英] Does postgresql support lookbehind regexp?

查看:133
本文介绍了postgresql支持在正则表达式后面吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果是,请提供一个后向示例或替代方法。

If yes, pls provide an example for lookbehind or an alternative.

我正在尝试提取不带'

select table_name,
       column_name,
       regexp_replace(substring(column_default from '''.*(?='')'),'''','','g') as sequence
FROM information_schema.columns 


推荐答案

我上次检查它在sql级别上不支持它,但是如果绝对必要,可以使用plperl解决该限制。 (但是,大量的正则表达式通常不属于数据库级别...)

It didn't support it at the sql level last I checked, but you can use plperl to work around the limitation if absolutely necessary. (Heavy regexing generally doesn't belong at the DB level, though...)

在您的特定示例中,请考虑使用否定类: [^'] (根据需要转义),或非贪婪通配符:。*?

In your particular example, consider using a negative class instead: [^'] (escape it as needed), or a non-greedy wildcard: .*?.

为此添加您的特定问题,除非您实际手动创建序列,否则其名称始终为:

Adding to this re your specific question, unless you actually create your sequence manually its name will always be:

tablename_colname_seq

另外,如果您在应用中使用多个架构和搜索路径,则以下两个默认值的行为也不同:

Also FWIW, the following two defaults have a different behavior if you use multiple schemas and search paths in your app:

nextval('foo'::regclass)  -- find foo once
nextval('foo'::text)      -- find foo each time

这篇关于postgresql支持在正则表达式后面吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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