Re: word wrap in postgres

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: word wrap in postgres
Date: 2011-04-12 17:59:27
Message-ID: 20110412175927.GA17933@tux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

akp geek <akpgeek(at)gmail(dot)com> wrote:

> Hi all -
>
> Is it possible to to split the data of a column into multiple
> lines. We are have a column which is text. when the query is excecuted, I
> wanted to display the text of the column in separate lines. Is it possible ?

Sure, for instace with a function like this:

test=*# select * from apk ;
t
----------------------------------------------------------------------------------------
this is a long line with text, i will try to split this line to display
multiple lines
(1 Zeile)

Zeit: 0,251 ms
test=*# create or replace function split_line(t text,count int) returns
text as $$declare i int;c int; ret text; begin ret:= t; i:=0;c:=0;for i
in 0 .. length(ret) loop if substring(ret,i,1) = ' ' then c:=c+1; end
if; if c = count then ret := overlay(ret placing E'\n' from i for 1);
c:= 0; end if; end loop; return ret; end; $$language plpgsql;
CREATE FUNCTION
Zeit: 0,537 ms
test=*# select split_line(t,3) from apk ;
split_line
------------------------
this is a
long line with
text, i will
try to split
this line to
display multiple lines
(1 Zeile)

Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message akp geek 2011-04-12 18:12:38 Re: word wrap in postgres
Previous Message Shianmiin 2011-04-12 17:48:54 Re: PostgreSQL backend process high memory usage issue