From: | "Claudio Lapidus" <clapidus(at)hotmail(dot)com> |
---|---|
To: | <pgsql-general(at)postgresql(dot)org> |
Subject: | "slicing" records |
Date: | 2003-10-11 05:00:03 |
Message-ID: | BAY7-DAV17wAddX47sF00000fe0@hotmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello
I have a table with objects' descriptions:
id | length
---------+--------
object1 | 40
object2 | 66
object3 | 12
object4 | 107
object5 | 220
But I need to export data to a legacy system that doesn't handle lengths
greater than 50 (don't ask me why...). Instead, it expects the data in this
format:
id | length | fragment | offst
---------+--------+----------+-------
object1 | 40 | whole | 0
object2 | 50 | start | 0
object2 | 16 | end | 50
object3 | 12 | whole | 0
object4 | 50 | start | 0
object4 | 50 | middle | 50
object4 | 7 | end | 100
object5 | 50 | start | 0
object5 | 50 | middle | 50
object5 | 50 | middle | 100
object5 | 50 | middle | 150
object5 | 20 | end | 200
So when length becomes greater, it is break up in as many pieces as
necessary, each of max allowed length except the last one, in such a way
that the sum of partial lengths equals the original one.
Now I couldn't manage to get a query capable of doing this. If anybody has
an idea, I'll be very much appreciated.
TIA,
cl.
From | Date | Subject | |
---|---|---|---|
Next Message | Christopher Kings-Lynne | 2003-10-11 05:20:43 | Re: go for a script! / ex: PostgreSQL vs. MySQL |
Previous Message | Dennis Gearon | 2003-10-11 03:18:31 | Re: int1? types? |