Alex Rivera | Logout

Does postgresql support lookbehind regexp?

Asked 2011-08-03T07:50:51.077
11

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

I'm trying to extract the sequence name without '

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

1 Answer

8

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
answered 2011-08-03T07:55:57.653

Your Answer