Re: [sqlalchemy] CheckConstraint in sqlalchemy-1.0.0dev

2015-02-27 Thread Christopher Singley


On Friday, 27 February 2015 09:52:36 UTC-6, Simon King wrote:
>
> On Fri, Feb 27, 2015 at 3:34 PM, Christopher Singley  > wrote: 
> > I'm using the latest dev version of sqlalchemy against postgresql-9.4.1 
> > 
> > I can't get SA to apply table-level CHECK constraints defined via 
> > declarative, although I can manually add them via psql to tables created 
> by 
> > SA Metadata.create_all() 
> > 
> > Here's the code I'm testing with: 
> > 
> > https://gist.github.com/csingley/7783779320359dd5f74c 
> > 
> > Am I doing something wrong? 
> > 
>
> I think you need to put your constraint into the __table_args__ attribute: 
>
>   
> http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/declarative/table_config.html
>  
>
> Hope that helps, 
>
> Simon 
>

Yep, that's what I was missing!  Makes sense syntactically.  Thank you sir. 
 

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


[sqlalchemy] CheckConstraint in sqlalchemy-1.0.0dev

2015-02-27 Thread Christopher Singley
I'm using the latest dev version of sqlalchemy against postgresql-9.4.1

I can't get SA to apply table-level CHECK constraints defined via 
declarative, although I can manually add them via psql to tables created by 
SA Metadata.create_all()

Here's the code I'm testing with:

https://gist.github.com/csingley/7783779320359dd5f74c

Am I doing something wrong?

-- 
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] inheritance with multiple foreign keys to the base table

2015-02-24 Thread Christopher Singley
Thanks!  Working for me now.

On Tue, Feb 24, 2015 at 2:31 PM, Michael Bayer 
wrote:

>
>
> Christopher Singley  wrote:
>
> > I'm using declared_attr.cascading from sqlalchemy-1.0.0dev to declare a
> foreign key on a subclass that also needs another separate foreign key
> reference to the parent table.
> > To let the Mapper know which column to join for the polymorphic
> inheritance relationship, I'm trying to pass an inherit_condition argument.
> >
> > Relevant code snippet can be seen here:
> > https://gist.github.com/anonymous/1b24768cb714fb9c7de7
>
> this is fixed in 3a56c4f019052c5d and your example case now succeeds.
>
>
> >
> > Importing this code generates this warning:
> > """
> > SAWarning: Implicitly combining column secinfo.id with column optinfo.id
> under attribute 'id'.  Please configure one or more attributes for these
> same-named columns explicitly.
> > """
> >
> > ...and then fails with this error:
> > """
> > sqlalchemy.exc.ArgumentError: Mapper Mapper|OPTINFO|optinfo could not
> assemble any primary key columns for mapped table 'Join object on
> secinfo(23263120) and optinfo(19756496)'
> > """
> >
> > How can I configure this correctly?
> >
> > --
> > 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.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "sqlalchemy" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sqlalchemy/a9IyAGKzr7M/unsubscribe.
> To unsubscribe from this group and all its topics, 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.
>

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


[sqlalchemy] inheritance with multiple foreign keys to the base table

2015-02-24 Thread Christopher Singley
I'm using declared_attr.cascading from sqlalchemy-1.0.0dev to declare a 
foreign key on a subclass that also needs another separate foreign key 
reference to the parent table.
To let the Mapper know which column to join for the polymorphic inheritance 
relationship, I'm trying to pass an inherit_condition argument.

Relevant code snippet can be seen here:
https://gist.github.com/anonymous/1b24768cb714fb9c7de7

Importing this code generates this warning:
"""
SAWarning: Implicitly combining column secinfo.id with column optinfo.id 
under attribute 'id'.  Please configure one or more attributes for these 
same-named columns explicitly.
"""

...and then fails with this error:
"""
sqlalchemy.exc.ArgumentError: Mapper Mapper|OPTINFO|optinfo could not 
assemble any primary key columns for mapped table 'Join object on 
secinfo(23263120) and optinfo(19756496)'
"""

How can I configure this correctly?

-- 
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] NUMERIC in sqlite

2010-10-06 Thread Christopher Singley
On Wed, Oct 6, 2010 at 10:12 AM, Michael Bayer  wrote:

> Well such a type wouldn't be backend agnostic.  The String/Integer wrapped 
> one would act very differently than a Numeric.   So not much point in a 
> transparent switch like that.   We try to keep "switches" like that to a 
> minimum (there are some, like Enum).
>

Makes sense.

A somewhat related follow-up question: is it possible to use
SQLAlchemy with "embedded" MySQL (libmysqld)?  If so, how?

On Wed, Oct 6, 2010 at 10:36 AM, Conor  wrote:

> "value / 10**4" will either truncate to an integer (Python 2) or return a
> float (Python 3 or with "from __future__ import division") if value is not
> divisible by 10**4. I think you want "decimal.Decimal(value) / 10**4"
> instead.

Good catch.  Obviously the pseudocode still had skid marks on it from
being pulled straight out of my butt; just trying to catch the sense
of sqlalchemy data model.

Thanks guys, it's appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] NUMERIC in sqlite

2010-10-06 Thread Christopher Singley
Thanks for the reply!

On Wed, Oct 6, 2010 at 9:06 AM, Michael Bayer  wrote:
> SQlite has no lossless DECIMAL type and SQLAlchemy can't work around that.

Well SQLAlchemy itself suggests workarounds that it doesn't implement,
so here we are...

> The approaches to working around this are:
> 1. store the decimals as strings.  Use String, and place a TypeDecorator
> around it which marshals Decimal objects.

Is it as simple as this?
"""
class DecimalString(sqlalchemy.types.TypeDecorator):
impl = sqlalchemy.types.String

def process_bind_param(self, value, dialect):
return str(value)

def process_result_value(self, value, dialect):
return decimal.Decimal(value)
"""

> 2. store the decimals as integers, using a type with a fixed exponent.   Use
> Integer, and place a TypeDecorator around it which multiplies Decimal
> objects upwards by the fixed exponent going in and back down going out.

Is it as simple as this?
"""
class DecimalInt(sqlalchemy.types.TypeDecorator):
impl = sqlalchemy.types.Integer

def process_bind_param(self, value, dialect):
return int(value * 10**4) # basis pt precision

def process_result_value(self, value, dialect):
return decimal.Decimal(value / 10**4) # basis pt precision
"""

> 3. stick with the FP program.

Who actually desires this behavior?  I'm not trying to flame here, I
am genuinely curious why that is the preferred default for SQLite.

One more question, if I may.  I suppose what would be ideal would be
to create a type that wrapped a String or Integer if the dialect was
sqlite, but wrapped a Numeric type if the dialect was something a
little more full-fledged.  Possible/difficult/ill-advised to do within
the SQLAlchemy type system?

Well, despite raising the ominous specter of accounting identity
violations, so far I'm really liking the looks of SQLAlchemy.  Thanks
for the help.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.