From: | "Andrus" <kobruleht2(at)hot(dot)ee> |
---|---|
To: | "Thom Brown" <thombrown(at)gmail(dot)com> |
Cc: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: How to implement word wrap |
Date: | 2010-03-30 09:32:24 |
Message-ID: | 799BE5F896AA4ED0AC51EE18191DC712@andrusnotebook |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | dipti shah | 2010-03-30 09:40:08 | Re: Get the list of permissions/privileges on schema |
Previous Message | Albe Laurenz | 2010-03-30 07:03:51 | Re: COPY ERROR |