Re: [sqlalchemy] Non negative integer column

2013-06-11 Thread Avishay Balderman
I prefer to have a server side solution... but cant find a generic one. On Monday, June 10, 2013 4:46:54 PM UTC+3, Michael Bayer wrote: Oh. Well a python side rule is very different from a server side rule, but if app side is all you need then sure you have a lot of options there. Use a

Re: [sqlalchemy] Non negative integer column

2013-06-10 Thread Avishay Balderman
Hi I am looking for a portable solution - A solution that will work when I switch from DB A to DB B. so I do not want to include any MySQL specific code. CheckConstraint looks promising.. but you mentioned it is not supported by MySQL. Any other ideas? Thanks Avishay On Monday, June 10, 2013

Re: [sqlalchemy] Non negative integer column

2013-06-10 Thread Avishay Balderman
How about using UserDefinedType http://docs.sqlalchemy.org/en/rel_0_8/core/types.html#sqlalchemy.types.UserDefinedType and declare a type 'NonNegativeInteger'. Will it be enough to protect the table from negative integers? On Monday, June 10, 2013 10:19:21 AM UTC+3, Avishay Balderman wrote:

Re: [sqlalchemy] Non negative integer column

2013-06-10 Thread Michael Bayer
Oh. Well a python side rule is very different from a server side rule, but if app side is all you need then sure you have a lot of options there. Use a TypeDecorator, check the docs there are many examples. Sent from my iPhone On Jun 10, 2013, at 4:30 AM, Avishay Balderman

Re: [sqlalchemy] Non negative integer column

2013-06-10 Thread Charlie Clark
Am 10.06.2013, 15:46 Uhr, schrieb Michael Bayer mike...@zzzcomputing.com: Oh. Well a python side rule is very different from a server side rule, but if app side is all you need then sure you have a lot of options there. Use a TypeDecorator, check the docs there are many examples. FWIW

[sqlalchemy] Non negative integer column

2013-06-09 Thread Avishay Balderman
Hi I would like to create a table with an integer column. This column value must be = 0. How can I enforce it using table defintion? i have looked here and it looks fine. http://docs.sqlalchemy.org/en/rel_0_8/core/schema.html?highlight=checkconstraint#sqlalchemy.schema.CheckConstraint Will it work

Re: [sqlalchemy] Non negative integer column

2013-06-09 Thread Rory Hart
from sqlalchemy.dialects.mysql import INTEGER as Integer my_int = Column(Integer(unsigned=True)) from: http://blog.luhn.com/post/20919696026/unsigned-integers-with-sqlalchemy-and-mysql Keep in mind, as Theron notes on his blog post, that this is MySQL specific so you won't have compatibility

Re: [sqlalchemy] Non negative integer column

2013-06-09 Thread Michael Bayer
have you considered just using an UNSIGNED INT ? MySQL offers support for such types. The CHECK constraint is a good way to go as well, but unfortunately I believe MySQL does not actually enforce CHECK constraints (funny, huh?) . Here's an SO question regarding that issue: