"slicing" records
От | Claudio Lapidus |
---|---|
Тема | "slicing" records |
Дата | |
Msg-id | BAY7-DAV17wAddX47sF00000fe0@hotmail.com обсуждение исходный текст |
Ответы |
Re: "slicing" records
Re: "slicing" records |
Список | 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.
В списке pgsql-general по дате отправления: