Re: back references using regex

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: back references using regex
Дата
Msg-id 20050908025753.GA57333@winnie.fuhr.org
обсуждение исходный текст
Ответ на Re: back references using regex  (Matthew Peter <survivedsushi@yahoo.com>)
Список 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

В списке pgsql-general по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: change column data type from smallint to integer
Следующее
От: "Milen A. Radev"
Дата:
Сообщение: Acting on dropped/timed-out connections