Re: How to implement word wrap - Mailing list pgsql-general

From Andrus
Subject Re: How to implement word wrap
Date
Msg-id 799BE5F896AA4ED0AC51EE18191DC712@andrusnotebook
Whole thread Raw
In response to Re: How to implement word wrap  (Thom Brown <thombrown@gmail.com>)
Responses Re: How to implement word wrap  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
List pgsql-general
> Just realised that's not what you're after, but my first point still
> stands.

Thank you.
I tried to wrap words at 15 characters using code below.

Issues:

1. Table rows places same word to multiple lines. How to remove them so that
every word appears only in single row?
2. In last select   sum(word||' ')  causes error. How to concatenate words
bact to row (inverse of unnest() function ?

Andrus.


create temp table words( id serial, word text ) on commit drop;
insert into words (word) select * from unnest(string_to_array('Quick brown
fox runs in forest.',' '));

create temp table results on commit drop as
select
  first.id as first,
  last.id as last,
  sum(length(a.word)+1) as charcount
from words a, words first, words last
where a.id between first.id and last.id
group by 1,2
having sum(length(a.word)+1)<15;

create temp table maxr on commit drop as
select
  first,
  max(charcount) as charcount
from results
group by 1;

create temp table rows on commit drop as
select
  first,
  last
from results
join maxr using (first,charcount)
order by 1;

select
  rows.first,
  sum(word||' ')
 from rows, words
where words.id between first and last
group by 1
order by 1, words.id


pgsql-general by date:

Previous
From: "Albe Laurenz"
Date:
Subject: Re: COPY ERROR
Next
From: dipti shah
Date:
Subject: Re: Get the list of permissions/privileges on schema