Converting strings to lower case and comparing them is not the same as a true
case-insensitive comparison. Python 3.3 adds a str.casefold method for this
reason. The docs for that method give a good explanation of the distinction:
"""Casefolding is similar to lowercasing but more aggressive beca
affiliation I fetch after the
flush incorrectly tells me that its street_address is None.
However, I don't see this being a problem in production and I think this
will work for our application. Thanks.
On Thursday, May 16, 2013 12:49:17 PM UTC-7, Michael Bayer wrote:
>
>
> On
Sounds like a useful feature.
Regarding case sensitivity, perhaps it would better if each of these
methods (even like() and contains()) took a keyword argument along the
lines of col.endswith('foo', case_sensitive=False) rather than adding extra
methods with weird names like iendswith.
On Mond
I think this value is coming from the underlying database driver rather
than SQLAlchemy. If you execute the stored proc directly using the driver
(I guess this is pymssql), do you see the same behavior?
On Thursday, May 16, 2013 12:37:56 PM UTC-7, John Anderson wrote:
>
> I have a SQLServer DB
I am trying to create a relationship to work with a legacy schema and am
having trouble configuring it to behave as I want. As a disclaimer, I
understand why the schema here is not the schema one would use if starting
from scratch.
Anyway, I have simplied the situation down to the following exa
the Python side is orderinglist:
> http://docs.sqlalchemy.org/en/rel_0_8/orm/extensions/orderinglist.htmland it
> works pretty well when you aren't dealing with the primary key.
>
>
>
>
>
> On May 7, 2013, at 1:03 AM, Bobby Impollonia >
> wrote:
>
> I am execut
I am executing a query with contains_eager to load objects and their
related objects from a different table. I would like to control the order
of the related objects within each InstrumentedList. I had hoped this could
be done through the ordering in the query.
For example, with a query like:
s
Thank you! That is exactly the function I needed.
On Tuesday, November 13, 2012 9:16:47 PM UTC-8, Michael Bayer wrote:
>
>
> On Nov 13, 2012, at 11:03 PM, Bobby Impollonia wrote:
>
> I have constructed a sample program consisting of two mapped classes
> (using sqlalchemy.ext
The behavior here isn't SQLAlchemy-specific. If you change:
class MyClass(Base):
__tablename__ = 'some_table'
id = Column(Integer, primary_key=True)
to
class MyClass(object):
pass
, you will see the same behavior.
On Tuesday, November 13, 2012 5:05:24 PM UTC-8, MikeParent wrote:
>
I have constructed a sample program consisting of two mapped classes (using
sqlalchemy.ext.declarative) that have a relationship/ backref between them.
At runtime the program does the following:
1) Print whether the parent class has an attribute for its relationship to
the child (declared as the
Hi. With SQLA 0.6.6, the program below fails on the last line with
ObjectDeletedError. Is this expected or a bug?
from sqlalchemy import create_engine, MetaData, Column, Unicode
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine(
I am constructing queries involving MSTimeStamp fields in MySQL and am
being receiving "Incorrect datetime value" warnings even in
situations where my queries are valid in MySQL.
How do I modify the following query so that sqlalchemy will accept it
without warning:
session.query(MyClass.id).filter
I am constructing queries involving MSTimeStamp fields in MySQL and am
being receiving "Incorrect datetime value" warnings even in
situations where my queries are valid in MySQL.
How do I modify the following query so that sqlalchemy will accept it
without warning:
session.query(MyClass.id).filter
You can also create a view mapped to that union and use that as a
virtual table so that you don't have to repeat the union specification
for every query:
http://www.w3schools.com/Sql/sql_view.asp
I don't know if that helps for SQLAlchemy though.
On Mon, Oct 26, 2009 at 5:59 PM, AF wrote:
>
>
>
You could also use a label to avoid the repetition:
from sqlalchemy.sql import desc
meta.Session.query(m.Hit.referer, func.count(m.Hit.id).label('count'))\
.group_by(m.Hit.referer)\
.order_by(desc('count'))
On Mon, Jun 22, 2009 at 2:22 AM, King
Simon-NFHD78 wrote:
>
>> -Or
Yes, it is safe. Python's underlying random number generation is
threadsafe. There is no need to create a new RNG each time to generate
a single number.
On Sun, Jun 21, 2009 at 1:53 PM, allen.fowler wrote:
>
>
>> default = lambda: random.randrange(1000,1)
>>
>
> Seems we crossed in the interw
default = lambda: random.randrange(1000,1)
On Sun, Jun 21, 2009 at 1:32 PM, AF wrote:
>
> Hello,
>
> Perhaps this is more of a Python question that SQLalchemy.. but...
>
>
> How can I assign a random number to a DB field by default?
>
>
> I tried:
> default = random.randrange(1000,1)
The error is complaining about the backref ("on relation
Royalty.owner"), so it makes sense that it would go away if you remove
the backref.
The error says that you need to specify foreign_keys for the backref,
so you should try that. i.e, change
backref='owner'
to
backref=backref('owner', fore
an tell them not to use
certain pages as sitelinks via the google webmaster tools. They'll
remove them, but they don't get replaced so you will have two fewer
sitelinks then.
On Thu, May 21, 2009 at 8:03 PM, Bobby Impollonia wrote:
>> otherwise if you have any advice on how to get 0
> otherwise if you have any advice on how to get 0.4/0.3
> delisted from such a prominent place on Google, that would be
> appreciated.
The simplest thing to do is to append:
Disallow: /docs/04/
Disallow: /docs/03/
to the file:
http://www.sqlalchemy.org/robots.txt
This tells google (and all we
Now the decorator swallows exceptions silently. You have to reraise
the exception after rolling back like Michael did. I believe the
correct form is:
def transaction(f):
def wrapper(*args, **kwargs):
try:
value = f(*args, **kwargs)
except:
session.rollb
rue)
>
>
> class Other(Base):
> __tablename__ = 'other'
> id = Column(Integer, primary_key=True)
> child1_id = Column(Integer, ForeignKey('child1.id'))
> child1_object = relation('Child1', backref='others', primaryjoin =
>
I am porting some code from SQLA .48 to .53 . I have a relation that
works in .48, but not in .53.
At the end of this post is a test program demonstrating the problem.
The program works in .48 but fails in .53 trying to understand the
child1_object relation . The error message says to add foreign
from sqlalchemy.sql import func
query = model.MyClass.query.order_by(func.date(model.MyClass.created_at))
This applies the sql "date" function to the column. That function
definitely exists in mysql; I'm not sure if it is standard, but if not
I'm sure you can find an equivalent function for whate
I am doing something similar. The following code works for me in SQLA .4.8
class Foo(Base):
__tablename__ = 'foo'
id = Column(Integer, primary_key=True)
bar_table = Table('bar', Base.metadata,
Column('parent_id', Integer, ForeignKey('foo.id'), nullable=False),
Column('child_id', I
It is not efficient at all to individually flush each of 20,000 new
rows to the database (the flush() happens implicitly via autoflush
when you query for the row) and read them back one by one. I would
change the primary key fields to auto increment in mysql so you don't
have to set them yourself
I think you have to use group by with a count(). Something like
Account.query.join(Account.users).group_by(Account.id).filter(func.count(User.id)
> 1)
On Mon, Jan 26, 2009 at 12:59 PM, Jon Nelson wrote:
>
> Let's assume I have a 1:many relationship between Accounts and Users.
>
> What I want (f
The declarative extension (sqlalchemy.ext.declarative) provides a
__init__ that takes keyword args for attributes (at least it does in
0.4).
On Tue, Jan 13, 2009 at 4:02 AM, Christoph Haas wrote:
> Thanks for the code. For those who might also be interested in an ORM base
> class providing __ini
he worker calls dispose()
before or during the sql stuff going on in the parent, but that
shouldn't mater, right? Is it possible that the call to dispose() is
somehow closing the connection in a way that sabotages the parent?
On Sun, Dec 21, 2008 at 11:32 PM, Michael Bayer
wrote:
>
>
> On
I occasionally have a query fail with 'Lost connection to MySQL server
during query' which gets converted into a
sqlalchemy.exceptions.OperationalError. I have not been able to figure
out why it happens, but the server should always be available.
I would like to tell sqlalchemy that if a query fa
e.
On Wed, Nov 19, 2008 at 1:25 PM, Moshe C. <[EMAIL PROTECTED]> wrote:
>
> 0.4.6
>
> On Nov 19, 11:12 pm, "Bobby Impollonia" <[EMAIL PROTECTED]> wrote:
>> What version of SQLA are you using? In .5 , you can pass individual
>> columns instead of a mapped
What version of SQLA are you using? In .5 , you can pass individual
columns instead of a mapped class to session.query.
On Wed, Nov 19, 2008 at 12:17 PM, Moshe C. <[EMAIL PROTECTED]> wrote:
>
> For Query there is an add_column() method, but I do not see a remove
> column method.
> Initializing a
Are you using declarative? If so, your class will have a property
called __table__
On Sun, Nov 16, 2008 at 4:04 PM, Moshe C. <[EMAIL PROTECTED]> wrote:
>
> Hi,
> Given a mapped ORM class, is it possible to retrieve from it the Table
> instabce to which it was mapped?
> TIA
> Moshe
>
> >
>
--~--~
If you are okay with only getting one record in the case of ties you can do
session.query(Snapshot).order_by(Snapshot.totalqty.desc()).first()
On Fri, Nov 7, 2008 at 12:22 PM, John Hunter <[EMAIL PROTECTED]> wrote:
>
> I am having trouble writing a sqlalchemy query which selects all rows
> where
If you have a session and then you fork, the child process is going to
try to use the same session but that won't work because connections
can't be floated across processes. If you call dispose() on the engine
in the child process after forking (e.g., metadata.bind.dispose() ),
then the child will
from sqlalchemy import not_
session.query(Region).filter(not_(Region.id.in_( (1,2,3) )))
alternately,
session.query(Region).filter(~ Region.id.in_( (1,2,3) ))
On Tue, Sep 2, 2008 at 6:59 AM, Artur Siekielski
<[EMAIL PROTECTED]> wrote:
>
> Hi.
> How can I use "...WHERE sth NOT IN (1, 4 ,5)" quer
The sqlalchemy update statement is documented here:
http://www.sqlalchemy.org/docs/05/sqlexpression.html#sql_update
Basically, you want something like
conn.execute(foo.update(values={foo.c.bar: 0 }))
On Tue, Jul 22, 2008 at 10:49 AM, Heston James - Cold Beans
<[EMAIL PROTECTED]> wrote:
> Guys,
I am using Column(Boolean) with declarative and MySQL and it is
working fine. In MySQL itself the type is 'tinyint(1)' but they
provide 'bool' and 'boolean' as synonyms if you prefer.
On Sat, Jul 19, 2008 at 7:48 AM, Heston James - Cold Beans
<[EMAIL PROTECTED]> wrote:
> Hello Guys,
>
>
>
> I'm l
>MyBase = type("MyBase", (Base, MyMixin), {})
Is this any different than just doing
class MyBase(Base, MyMixin): pass
?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this gro
If I am using the mysql-specific Column constructs with the charset
option, will things be automatically encoded/ decoded by SA using that
charset? Or is the charset option only used for Create Table?
On Thu, Jun 26, 2008 at 7:20 PM, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
> first of all, the
If you do them as double percent signs ( '%%') then the python string
formatting will replace them with single percent signs.
On Fri, Jun 27, 2008 at 9:12 AM, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
>
> Hi.
>
> I want to do robust algorithm for searching in tables...the simplest
> example is
In mysql you can declare a integer column to be auto_increment and it
will handle for you giving each row a different number. Other
databases have similar mechanisms. It sounds like the invoice number
is the primary key for the invoice table? If you have a integer
primary key in sqlalchemy, it ass
Does SA support the following scenario? :
I have a class (let's call in User). I have a many-to-many
relationship between Users and urls where a url is just a string. So I
want to have a secondary table where one column is a foreign key on
User and the other is a string.
If the second column wher
The mapper for the base class has a property called polymorphic_map
which is a dictionary whose keys are the discriminator values and
whose values are the mappers of the associated classes (you can get
from there to the actual class via the mapper's class_ property).
I can't speak to whether this
You can add
.order_by(None)
to the query to remove the default ordering.
On Fri, May 30, 2008 at 12:25 PM, Geoff <[EMAIL PROTECTED]> wrote:
>
> Hi!
>
> I've noticed that a very simple query has an ordering applied to it
> even though I haven't asked for one. Is there a way to stop it doing
> that
ny
> coverage for this exact scenario and there wasn't any "aliasing" logic
> removed AFAIK.
>
>
> On May 21, 2008, at 12:07 PM, Bobby Impollonia wrote:
>
>>
>> Hi. If I have a many-to-many relation between Class1 and Class2, the
>> following query:
Hi. If I have a many-to-many relation between Class1 and Class2, the
following query:
Class1.query.filter(Class1.class2s.contains(obj1)).filter(Class1.class2s.contains(obj2))
, where obj1 and obj2 are instances of Class2, generates the following
sql in .4.6:
SELECT
FROM class1, secondary
WHERE c
Any idea when a .deb will be available?
http://packages.debian.org/unstable/python/python-sqlalchemy is still .4.5
On Wed, May 14, 2008 at 3:02 PM, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
> SQLAlchemy 0.4.6 is now available at:
>
> http://www.sqlalchemy.org/download.html
>
> This release inclu
I dont see how this:
cls.query.left_bracket().filter_or(cls.y ==
17).filter_or(cls.x==27).right_bracket()
is clearer than this:
cls.query.filter(or_(cls.y == 17, cls.x==27))
Also, another vote for cutting off python 2.3. Seriously, it's 2008.
On Mon, May 12, 2008 at 11:58 AM, <[EMAIL PROTECTED]
in_ is a method that exists on a column. You pass it the list of
things that the column value should be in. For example, if you have a
class called MyClass that is mapped to a table and has a column called
id, you can do:
session.query(MyClass).filter(MyClass.id.in_( [ 3, 4] )).all()
On Fri, Ma
Another issue with this relation is that it doesn't like being eagerloaded.
Using the same model from my first post (with the broken backref
removed or fixed):
session.query(Child1).options(eagerload('left_child2')).first()
Generates the sql:
SELECT anon_1.child1_id AS anon_1_child1_id, anon_1.pa
> I'd try bypassing their SQLA integration altogether if thats possible
It isn't possible if you are relying on the turbogears identity system
(cookie-based visitor tracking and access control).
--~--~-~--~~~---~--~~
You received this message because you are subsc
ise if multiple rows
were returned.
On Wed, May 7, 2008 at 8:22 PM, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
>
>
> On May 7, 2008, at 7:23 PM, Bobby Impollonia wrote:
>
> >
> > secondary_table = Table('secondary', Base.metadata,
> >Column(
secondary_table = Table('secondary', Base.metadata,
Column('left_id', Integer, ForeignKey('parent.id'), nullable=False),
Column('right_id', Integer, ForeignKey('parent.id'), nullable=False))
class Parent(Base):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
cl
I thought that defining relation with a backref was just a convenient
shorthand for defining two relations. This makes it sound like are
practical differences between the two techniques. Is this true? What
are the differences?
Also, does having the unique key that you recommend stop SA from
tryin
I have a class that I will call Child which inherits via join
inheritance from a class I will call Parent. There is a many-to-many
relationship between Child and a class that I will call Other.
A query that looks like this:
child =
Other.query.filter(not_(other.child_objects.contains(child))).fi
Awesome. For now, the inherit_condition mapper arg is working fine, so
thanks for that.
On Thu, May 1, 2008 at 9:03 PM, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
>
> On May 1, 2008, at 6:25 PM, Bobby Impollonia wrote:
>
> >
>
> > It no longer works. In partic
Hi. I have two tables that have foreign keys on each other. The
following works fine, where Base is a declarative base:
class Child1(Base):
__tablename__ = 'child1'
id = Column('id', Integer, primary_key=True)
related_child2 = Column('c2', Integer, ForeignKey('child2.id',
use_alter = T
Yes, you can have the same class be associated with different tables
at different times.
Sqlalchemy uses a 'maper' to associate a class with a table. You can
define multiple mappers for the same class that map it to different
tables. One of these will be the primary mapper and will be used by
def
You could specify that fullname is null (None) for the columns that
don't have a full name value.
On Mon, Apr 7, 2008 at 8:04 AM, Carla <[EMAIL PROTECTED]> wrote:
>
> Hello all
>
> I'd like to insert more than one expression in a table. Some
> expressions don't have an entry in every column:
>
I like having the base of my models be .model.Base . That
name does a good job of describing what role the class plays; it is
the common base on which each model is built.
If I were mixing declarative and non-declarative models, then I could
understand wanting the declarative ones to be distingui
Hi. I have a simple model that looks like this:
Base = declarative_base(metadata=metadata)
class Item(Base):
__tablename__ = 'item'
id = Column('id', Integer, primary_key=True)
group = Column('group', Integer)
Groups have no useful information other than the items they contain,
so I
f the keys is the one to have use_alter)?
On Tue, Apr 1, 2008 at 6:54 PM, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
>
> On Apr 1, 2008, at 5:59 PM, Bobby Impollonia wrote:
>
> >
> > This fails (as expected) because of the circular dependency. Before I
> > swit
Hi. I am using sqlalchemy with a database that has two tables that
each have foreign keys on the other.
The situation this is modeling is a tree where the levels alternate
between two different types of node. Each Node1 has a parent of type
Node2 (or null for the root) and each Node2 has a parent
That will set the default in python, not in sql. If it really needs to
be in the create table statements, use PassiveDefault:
http://www.sqlalchemy.org/docs/04/metadata.html#metadata_defaults_passive
On Sun, Mar 30, 2008 at 2:30 PM, Andreas Jung <[EMAIL PROTECTED]> wrote:
>
>
> --On 31. März 2008
If the only dict behavior you need is accessing elements with [],
another approach is that you could implement __getitem__ in your model
but not inherit from dict.
On Sat, Mar 29, 2008 at 3:08 PM, Mike Bernson <[EMAIL PROTECTED]> wrote:
>
> I am trying to use models that inherit from dict.
>
>
t; On Mar 29, 2008, at 9:13 AM, Bobby Impollonia wrote:
>
>
>
>
>
> > Hi. I recently switched a sqlalchemy project from using manual mapping
> > of classes to ext.declarative.
>
> > This is in a turbogears project and I am using their metadata and
> > ma
Hi. I recently switched a sqlalchemy project from using manual mapping
of classes to ext.declarative.
This is in a turbogears project and I am using their metadata and
mapper. Before I had:
from turbogears.database import metadata, mapper
users_table = sqlalchemy.Table('users', metadata, ... )
c
68 matches
Mail list logo