Re: [sqlalchemy] python customer function

2015-05-11 Thread Jose Soares

thanks for point me to this docs, Jonathan, I'm going to take a look at it.
j
On 08/05/2015 23:30, Jonathan Vanasco wrote:
Would you be able to use a TypeDecorator? 
 http://docs.sqlalchemy.org/en/latest/core/custom_types.html#sqlalchemy.types.TypeDecorator 



That will allow you to define a function for handling how sqlalchemy 
inserts and accesses the data from sql.

--
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.


Re: [sqlalchemy] python customer function

2015-05-08 Thread Jose Soares

Hi Mike, thanks to reply my question.
In my case the extract function is unuseful because it needs a datetime 
to extract parts of it

but I don't have a datetime but a codified date.
I need to manage a string which is a personal code with info about name, 
birthday, birth place and gender.
Infact the birth month is represented by a single letter (not in 
sequential order)


A=jan
B=feb
C=mar
D=apr
E=may
F= -
G= -
H=jun
I= -
J= -
K= -
L=jul
M=aug
N= -
O= -
P=sep
Q= -
R=oct
S=nov
T=dec



the day contains also the gender, (female is incremented of 40)
the birth year has only 2 digits.

Examples:

60R11 = 1960-10-11 male
60R51 = 1960-10-11 female
00T41 = 1900-12-01 female
00T01 = 1900-12-01 male

I'm looking for a function to decode such string.
I thought I could create a python function to manage it.

j


On 07/05/2015 22:01, Mike Bayer wrote:



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), '-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 
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.


Re: [sqlalchemy] python customer function

2015-05-08 Thread Jonathan Vanasco
Would you be able to use a TypeDecorator? 
 
http://docs.sqlalchemy.org/en/latest/core/custom_types.html#sqlalchemy.types.TypeDecorator

That will allow you to define a function for handling how sqlalchemy 
inserts and accesses the data from sql.

-- 
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.


Re: [sqlalchemy] python customer function

2015-05-07 Thread Mike Bayer



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), '-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.