X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 1E685D1D1BB for ; Thu, 29 Jan 2004 15:04:08 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 64718-01 for ; Thu, 29 Jan 2004 11:03:46 -0400 (AST) Received: from noon.pghoster.com (noon.pghoster.com [64.246.0.64]) by svr1.postgresql.org (Postfix) with ESMTP id 664CAD1D179 for ; Thu, 29 Jan 2004 11:03:36 -0400 (AST) Received: from [61.94.40.210] (helo=winxp) by noon.pghoster.com with asmtp (Exim 4.24) id 1AmDhp-0000DF-1i for pgsql-sql@postgresql.org; Thu, 29 Jan 2004 09:03:46 -0600 Message-ID: <010301c3e679$077698b0$5444053d@winxp> From: "Chris Travers" To: Subject: How to retrieve N lines of a text field. Date: Thu, 29 Jan 2004 22:01:59 +0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - noon.pghoster.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - travelamericas.com X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200401/263 X-Sequence-Number: 16656 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