From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Matthew Peter <survivedsushi(at)yahoo(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: back references using regex |
Date: | 2005-09-08 02:57:53 |
Message-ID: | 20050908025753.GA57333@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, Sep 07, 2005 at 05:26:07PM -0700, Matthew Peter wrote:
> Thanks. I'll check it out asap. I didn't realize the
> regex expressions needed to be escaped for it to be a
> valid expression.
If you use ordinary quotes (') around the regular expression then
you have to escape the backslashes because there's an extra level
of string parsing that you're probably unaccustomed to. If you use
dollar quotes (available since 8.0) then you don't need the extra
escapes:
SELECT id, substring(content FROM $$((\S+\s*){1,3})$$) FROM article;
> Would it be possible to choose what paragraph to use in a summary?
You might be able to use split_part(). For example, if paragraphs
are separated by pairs of newline (\n) characters, then the following
should return each article's third paragraph:
SELECT id, split_part(content, '\n\n', 3) FROM article;
See "String Functions and Operators" and "Pattern Matching" in the
documentation for more information. If you need to get fancy then
consider writing a function in a language like PL/Perl.
--
Michael Fuhr
From | Date | Subject | |
---|---|---|---|
Next Message | Matt | 2005-09-08 06:53:05 | Bash script to update sequences |
Previous Message | Alvaro Herrera | 2005-09-08 02:50:39 | Re: change column data type from smallint to integer |