What Jakub said. Do it directly in Postgres. It isn't at all clear why you would want all the overhead of JSON for this. If you must do it in Python, use a library that deals with geometries directly, such as shapely of fiona.
– John PowellMay 14 '15 at 9:17

Well... I tried doing it as a Postgres function, but as it would then all be one big transaction, it fails as there are too many queries. Basically what I need to do is to figure out if a line is too long and if so, I need to cut it into pieces. I know that the JSON part is slowing everything down like crazy... that's why I'd like to get rid of it... I'll have a look at shapely
– GeorgMay 14 '15 at 13:42

There is no way of doing it directly as a postgres function but forcing it not to do everything in one transaction but to write the data after some loops, right?
– GeorgMay 14 '15 at 13:45

you are super awesome!!!! thank you so much for your help!!!!
– GeorgMay 17 '15 at 18:10

One more question... So, once I have a row, I'd like to figure out it's length. shapely_geometry.ST_Length() didn't did the trick for me. And once I have it I'd need to run ST_Line_Substring to split the line. Sorry to bother you, but my python skills are very limited... would be so super awesome if you might tell me how to do those two commands!!!
– GeorgJun 2 '15 at 11:32

I managed to figure it out! What took 2 weeks before took 6hours now :) thanks again!!!!
– GeorgJun 3 '15 at 6:06