Skip site navigation (1) Skip section navigation (2)

How to retrieve N lines of a text field.

From: "Chris Travers" <chris(at)travelamericas(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: How to retrieve N lines of a text field.
Date: 2004-01-29 15:01:59
Message-ID: 010301c3e679$077698b0$5444053d@winxp (view raw or flat)
Thread:
Lists: pgsql-sql
Hi all;

This is a complex issue, and i am tryign to figure out how to use regular
expressions to resolve this issue.  I need to retrieve the first N lines of
a text field.  N would be assigned using a parameterized query, if possible.

I had thought about using something like:
select substring(test from '#"' || repeat('%\n', $1) || '#"%' for '#') from
multiline_test;
However, this always selects every line but the final one (because %\n seems
to be interpreted to be the largest possible string, while I want it to be
the smallest possible string).

Is there a workaround?  Any other help?  Or do I need to write a UDF?

Best Wishes,
Chris Travers


Responses

pgsql-sql by date

Next:From: Alexandra BirchDate: 2004-01-29 15:02:06
Subject: Re: limit 1 and functional indexes
Previous:From: Achilleus MantziosDate: 2004-01-29 15:01:43
Subject: Re: query not using index for descending records?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group