On 5/7/15 9:10 AM, jo wrote:
Hi all,
I would like to create a python customer function to extract data from a
table column and return a calculated value as in:
def birth(data):
mm =
dict(A='01',B='02',C='03',D='04',E='05',H='06',L='07',M='08',P='09',R='10',S='11',T='12')
return '19'+data[6:8] +'-'+ mm[data[8:9]] +'-'+ data[9:11]
sa.func.to_date( birth(Anagrafica.c.dato_fiscale), 'YYYY-mm-dd'))
in: Anagrafica.c.dato_fiscale='ZZZHHH54M11Z128Y'
out: '1954-08-11'
How can I do this in a sqlalchemy query?
look into using the extract() function:
http://docs.sqlalchemy.org/en/rel_1_0/core/sqlelement.html?highlight=extract#sqlalchemy.sql.expression.extract
it mostly works the same on all backends, here's PG's docs:
http://www.postgresql.org/docs/8.1/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
thanks for any help.
j
--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.