Zwieberl
2012-12-13 10:03:42 UTC
Hello,
I am very happy with using sqlalchemy 0.8 so far.
But now I stumpled upon a problem I could not solve:
I have strings like 'POINT(-141.1643 32.42112)' and want to extract the
numbers between the brackets.
Note1: I can not use python to manipulate the string, since the string gets
created from a Postgresql-function-call within the select-statement, and
the substring has to be available in the same select.
Note2: the length of the numbers is not constant, therefore a simple
substring()-call is not possible, since I dont know the end-value.
Now, since "POINT(" is always the same I could use
trim(leading "POINT(" from x), as well as
trim(trailing ")" from x)
to get rid of everything outside the brackets.
But how can I use the trim-function in sql-Alchemy?
I tried sqlalchemy.func.trim('leading', '"POINT("' ,x)
-> error: function pg_catalog.btrim(unknown, unknown, text) does not exist
and sqlalchemy.func.trim('leading "POINT(" from ' + x)
-> returns just the whole string 'leading "POINT(" from POINT(32.233 4.42)'
Does anyone know how to use trim in sqlalchemy correctly?
Any help would be appreciated! (Also if you have a different approach
towards extracting the substring from the string)
Thank you all!
I am very happy with using sqlalchemy 0.8 so far.
But now I stumpled upon a problem I could not solve:
I have strings like 'POINT(-141.1643 32.42112)' and want to extract the
numbers between the brackets.
Note1: I can not use python to manipulate the string, since the string gets
created from a Postgresql-function-call within the select-statement, and
the substring has to be available in the same select.
Note2: the length of the numbers is not constant, therefore a simple
substring()-call is not possible, since I dont know the end-value.
Now, since "POINT(" is always the same I could use
trim(leading "POINT(" from x), as well as
trim(trailing ")" from x)
to get rid of everything outside the brackets.
But how can I use the trim-function in sql-Alchemy?
I tried sqlalchemy.func.trim('leading', '"POINT("' ,x)
-> error: function pg_catalog.btrim(unknown, unknown, text) does not exist
and sqlalchemy.func.trim('leading "POINT(" from ' + x)
-> returns just the whole string 'leading "POINT(" from POINT(32.233 4.42)'
Does anyone know how to use trim in sqlalchemy correctly?
Any help would be appreciated! (Also if you have a different approach
towards extracting the substring from the string)
Thank you all!
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/VepaVySkkGMJ.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/VepaVySkkGMJ.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.