Am 26.11.2011 15:26 schrieb Mark Erbaugh m...@microenh.com:
I'm using a ColumnMixin to have a subset of columns common in two tables. Is
there an easy way to populate the common columns in one descendent table with
the corresponding columns in a row of the other descendent tables
I'm using a ColumnMixin to have a subset of columns common in two tables. Is
there an easy way to populate the common columns in one descendent table with
the corresponding columns in a row of the other descendent tables, and can this
be a method of the ColumnMixin class? Ideally, I'd like
I'm trying to use data from a sequence to add columns to a SQLAlchemy table
created declaratively. Here's what I'm doing:
class Sizing(Base):
__tablename__ = 'sizing'
id = Column(Integer, primary_key=True)
[...]
for name in ('column1', 'column2', 'column3', ...):
x =
On Nov 10, 2011, at 12:57 PM, Michael Bayer wrote:
On Nov 10, 2011, at 9:34 AM, Mark Erbaugh wrote:
I'm trying to use data from a sequence to add columns to a SQLAlchemy table
created declaratively. Here's what I'm doing:
class Sizing(Base):
__tablename__ = 'sizing'
id = Column
On Nov 4, 2011, at 4:54 AM, Stefano Fontanelli wrote:
Il 04/11/11 03.08, Mark Erbaugh ha scritto:
On Nov 3, 2011, at 2:54 PM, Stefano Fontanelli wrote:
Il 03/11/11 19.18, Mark Erbaugh ha scritto:
Using the query object count() method generates a sub-query (as per the
docs). The docs
Using the query object count() method generates a sub-query (as per the docs).
The docs say to use func.count to avoid the subquery. func.count seems to
require a field object. Is there a way to generate a query that essentially
becomes 'select count(*) from table' using the ORM, not the SQL
On Nov 3, 2011, at 2:54 PM, Stefano Fontanelli wrote:
Il 03/11/11 19.18, Mark Erbaugh ha scritto:
Using the query object count() method generates a sub-query (as per the
docs). The docs say to use func.count to avoid the subquery. func.count
seems to require a field object. Is there a way
On Nov 3, 2011, at 3:31 PM, werner wrote:
Mark,
On 11/03/2011 07:18 PM, Mark Erbaugh wrote:
Using the query object count() method generates a sub-query (as per the
docs). The docs say to use func.count to avoid the subquery. func.count
seems to require a field object. Is there a way
What's the recommended way to count the rows in a table. In SQL, I would
typically use select count(*) from table;
The statement session.query(table).count() issues a count(*) on a sub-query.
The docs say for finer control to use func.count
i.e. session.query(func.count(table.column)). That
On Oct 15, 2011, at 10:17 AM, Michael Bayer wrote:
On Oct 14, 2011, at 9:45 PM, Mark Erbaugh wrote:
There are two tables pump and curve. The curve table has three fields,
curve_pn, head and gpm. The design is that the rows with the same curve_pn
value represent x,y points (head,gpm
There are two tables pump and curve. The curve table has three fields,
curve_pn, head and gpm. The design is that the rows with the same curve_pn
value represent x,y points (head,gpm) on a pump performance curve. Each row in
the pump table has a curve_pn column that links to the performance
Let's say there is a mapped (declaratively, but that shouldn't matter) class,
Data, that has fields Data.value1, ... Data.value10.
There is also an instance of this class, data that is populated from the data
table.
Obviously, you can get the values using data.value1, ...
But is there a
On Sep 6, 2011, at 2:48 PM, Michael Bayer wrote:
On Sep 6, 2011, at 2:38 PM, Mark Erbaugh wrote:
Let's say there is a mapped (declaratively, but that shouldn't matter)
class, Data, that has fields Data.value1, ... Data.value10.
There is also an instance of this class, data
On Aug 18, 2011, at 7:01 PM, Mark Erbaugh wrote:
On Aug 18, 2011, at 6:06 PM, Mark Erbaugh wrote:
want to create a table that has several similar fields. For example, assume
the fields are field1, field2, ...
Is there a way in the declarative class that I can do something like
On Aug 19, 2011, at 10:41 AM, Michael Bayer wrote:
Id use a mixin so that a superclass can be generated in a data driven manner:
MyCols = type(MyCols, (object, ), dict((field%d % i, Column(Integer)) for
i in xrange(1, 10)))
class MyClass(MyCols, Base):
...
otherwise if you want
I have a table that has a foreign key field that is optional. IOW, the current
row may be linked to at most one row in the foreign table. If the foreign key
field is not NULL, it must point to a valid row in the foreign table, but if it
is NULL that means that it it not linked.
Is there an
On Aug 19, 2011, at 2:10 PM, Mike Conley wrote:
class Parent(Base):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
class Child(Base):
__tablename__ = 'child'
id = Column(Integer, primary_key=True)
p_id = Column(Integer, ForeignKey(Parent.id))
I want to create a table that has several similar fields. For example, assume
the fields are field1, field2, ...
Is there a way in the declarative class that I can do something like:
for i in range(10):
'field%d' % i = Column( ... )
Thanks,
Mark
--
You received this message because
On Aug 18, 2011, at 6:06 PM, Mark Erbaugh wrote:
want to create a table that has several similar fields. For example, assume
the fields are field1, field2, ...
Is there a way in the declarative class that I can do something like:
for i in range(10):
'field%d' % i = Column
Me again (see below):
On Aug 18, 2011, at 7:01 PM, Mark Erbaugh wrote:
On Aug 18, 2011, at 6:06 PM, Mark Erbaugh wrote:
want to create a table that has several similar fields. For example, assume
the fields are field1, field2, ...
Is there a way in the declarative class that I can do
On Aug 17, 2011, at 10:15 AM, Conor wrote:
On 08/17/2011 12:01 AM, Mark Erbaugh wrote:
Is it possible to group or order by a field in a many to one related table?
class Rental(Base):
__tablename__ = 'rental'
rental_id = Column(Integer, autoincrement=True, primary_key=True
Is it possible to group or order by a field in a many to one related table?
class Rental(Base):
__tablename__ = 'rental'
rental_id = Column(Integer, autoincrement=True, primary_key=True)
inventory_id = Column(Integer, ForeignKey(Inventory.inventory_id),
nullable=False)
On Aug 12, 2011, at 10:21 AM, RVince wrote:
I'm trying to discern a means of creating a .filter(A rel B) where the
values for A, rel and B come from an parameters passed in to the web
page.
I already have an SQLAlchemy statement, say
query = Session.query(table).filter(A==B)
and I want
On Aug 12, 2011, at 11:52 AM, NiL wrote:
say you want to filter on the 'field' (field would be a string representing
the name of the field) on objects of class == Klass
field_attr = getattr(Klass, field)
would give you the instrumented attribute
then
Is there a way to access the parameters to the Column() call used to set up a
database table when given either an instance field or class field?
For example:
class MyClass(Base):
...
f1 = Column(Integer, nullable=False, info={'min':0})
...
If I have MyClass.f1 or
On Aug 12, 2011, at 5:26 PM, Michael Bayer wrote:
Is there a way to access the parameters to the Column() call used to set up
a database table when given either an instance field or class field?
For example:
class MyClass(Base):
...
f1 = Column(Integer, nullable=False,
On Aug 6, 2011, at 7:18 AM, Mike Conley wrote:
You can get to the column default value.
class MyTable(Base):
__tablename__ = 'table'
id = Column(Integer, primary_key=True)
name = Column(String, default='new name')
def __init__(self, name=None):
In a declaratively created table, is there an automatic way to get a new
instance of the class object to be populated with values specified in a
'default' clause?
i.e.
class MyTable(Base):
__tablename__ = 'table'
name = Column(String, default='new name')
...
newRow =
In my application, some tables have several fields that need to have the same
type and default value, i.e.:
field1 = Column(Integer, default=2)
field2 = Column(Integer, default=2)
...
Is there some way to refactor the Common(Integer, default=2), short of creating
a custom column type? I could
On Aug 5, 2011, at 2:00 PM, Stefano Fontanelli wrote:
Il 05/08/11 19.29, Mark Erbaugh ha scritto:
In a declaratively created table, is there an automatic way to get a new
instance of the class object to be populated with values specified in a
'default' clause?
i.e.
class MyTable(Base
On Aug 5, 2011, at 3:51 PM, Michael Bayer wrote:
On Aug 5, 2011, at 1:36 PM, Mark Erbaugh wrote:
In my application, some tables have several fields that need to have the
same type and default value, i.e.:
field1 = Column(Integer, default=2)
field2 = Column(Integer, default=2
On Aug 4, 2011, at 9:22 AM, Michael Bayer wrote:
The range of speedups here would be between 30% and 80%, with direct usage of
connection/session .execute() with Table metadata giving you the 80%.
Thanks. I'll look into your suggestions
I'm not sure what transaction is in
On Aug 4, 2011, at 9:22 AM, Michael Bayer wrote:
On Aug 3, 2011, at 8:38 PM, Mark Erbaugh wrote:
I'm using SA (with SQLite) with a schema like:
A - B - C - D
where - means that the tables have a one to many relationship
I'm populating a sample data set where there are 25 rows
Table A has a one to many relationship with Table B. There may be zero or more
rows in B for each row in A.
I would like to have a query that retrieves all the rows in table A joined with
the first related row in table B (if one exists). In this case, each row in
table B has a DATE field and
(date=datetime.date(2011, 9, 17)),
]),
])
s.commit()
for obj in s.query(A).options(joinedload(A.latest_b)):
print obj.latest_b
On Aug 4, 2011, at 5:55 PM, Mark Erbaugh wrote:
Table A has a one to many relationship with Table B. There may be zero or
more rows in B
I'm using SA (with SQLite) with a schema like:
A - B - C - D
where - means that the tables have a one to many relationship
I'm populating a sample data set where there are 25 rows in A, 25 rows in B
for each row in A, 25 rows in C for each row in B and 25 rows in D for each row
in C. This
I'm trying to follow the instructions in the SA docs regarding Unicode and
SQLite. I've declared all my character fields as either Unicode or
UnicodeText. When populating the data, I specify strings as unicode strings
(u'string'), but I'm still getting an warning: SAWarning Unicode type
On Aug 2, 2011, at 6:50 PM, Michael Bayer wrote:
On Aug 2, 2011, at 6:35 PM, Mark Erbaugh wrote:
I'm trying to follow the instructions in the SA docs regarding Unicode and
SQLite. I've declared all my character fields as either Unicode or
UnicodeText. When populating the data, I
My program accesses a sqlite database. It only extracts data from the database,
it never writes anything to it. It can also be assumed that the database is
not updated by other processes. In reality, the database is completely replaced
periodically by a new version, but the program can be shut
On Jun 19, 2011, at 10:06 AM, Michael Bayer wrote:
Look into using a TypeDecorator around String.
process_bind_param() and process_result_value() would coerce the data between
string / Python date.
http://www.sqlalchemy.org/docs/core/types.html#augmenting-existing-types
some
On Jun 18, 2011, at 6:37 AM, Tomasz Jezierski - Tefnet wrote:
How about: http://code.google.com/p/sqlautocode/ ?
Thanks for the pointer. That's just the kind of module I was looking for.
--
You received this message because you are subscribed to the Google Groups
sqlalchemy group.
To post
On Jun 18, 2011, at 10:37 AM, Michael Bayer wrote:
reflection is not a fast process at all since it aims to be comprehensive.
The MetaData, Table and everything related is pickleable for the purpose of
apps that want to cache the results of reflection in a file, to be pulled out
later.
I have a legacy database where dates are stored in the format mm/dd/ (i.e.
06/18/2011). Is it possible to adapte the Sqlalchemy DATE() type to use this
format? If not, is is possible to create a new class to handle this format?
Thanks,
Mark
--
You received this message because you are
Is there overhead associated with reflection? When SA is used in a stateless
web server, I think it would have to do the reflection every time a new page is
served. Is there a way to create and reuse a snapshot of the reflection
results.
I guess what I'm asking is if I write manual code that
On Nov 22, 2010, at 5:38 AM, A. S. wrote:
Hi!
at the company I work for I'd like to propose introducing Python to
replace the hopelessly outdated SAS scripts. SQLAlchemy seems like a
good option for SQL handling and I can imagine modules specifically
tailored to our needs.
However, the
Please refer to the Joined Table Inheritance Section under declarative.ext (I'm
using SA 0.5.8).
Is is possible to create a Person who is both an Engineer and a Manager using
joined table inheritance? IOW, both Manager and Engineer would link to the same
row in Person.
Thanks,
Mark
--
You
On Oct 31, 2010, at 3:08 PM, Daniel Meier wrote:
Hi list
I have tried the examples in the ORM tutorial and I'm wondering how I
can separate different models into own modules.
Let's say I have a BankAccount model and a BankCustomer model. My
idea would be to create two modules,
On Oct 29, 2010, at 6:12 AM, Dan @ Austria wrote:
Hi,
i have a question to database/design specialist. How can (should!) i
implement a stock management system in sql-alchemy and python? I get
the following data from another system via files
- movements: bills from a scanner at a cash
How do people handle Decimal data with SA / SQLite? Newer versions of SA give
the following warning:
SAWarning: Dialect sqlite+pysqlite does *not* support Decimal objects natively,
and SQLAlchemy must convert from floating point - rounding errors and other
issues may occur. Please consider
I have a table (T) that has a many-to-one relationship (via foreign key
inclusion) to a category table (C). Let's name the relationship category. When
I retrieve an existing T record, SA populates the category field with an
instance of C. I can change the category to a different value by
On Oct 29, 2010, at 6:18 PM, Michael Bayer wrote:
How do people handle Decimal data with SA / SQLite? Newer versions of SA
give the following warning:
SAWarning: Dialect sqlite+pysqlite does *not* support Decimal objects
natively, and SQLAlchemy must convert from floating point -
On Oct 29, 2010, at 9:39 PM, Conor wrote:
I have a table (T) that has a many-to-one relationship (via foreign key
inclusion) to a category table (C). Let's name the relationship category.
When I retrieve an existing T record, SA populates the category field with
an instance of C. I can
I have a data graph mapped as:
class BatchDetail(BASE):
__tablename__ = TABLE_BATCH_DET
id = Column(Integer, primary_key=True)
batch = Column(ForeignKey(TABLE_BATCH_HDR + '.id'))
account_id = Column(ForeignKey(TABLE_L3_ACCT + '.id'))
# other fields
#
On Oct 27, 2010, at 2:36 PM, Mark Erbaugh wrote:
I have a data graph mapped as:
class BatchDetail(BASE):
__tablename__ = TABLE_BATCH_DET
id = Column(Integer, primary_key=True)
batch = Column(ForeignKey(TABLE_BATCH_HDR + '.id'))
account_id = Column(ForeignKey
Does SA maintain a usable unique identifier for newly added child records
before the data is committed?
I have a mapping of a one-many relationship using a foreign key. The detail
(many side) records are in an instrumented list. I need to relate the items in
this list to rows in an user
On Oct 25, 2010, at 3:57 PM, Michael Bayer wrote:
On Oct 25, 2010, at 2:19 PM, Mark Erbaugh wrote:
Does SA maintain a usable unique identifier for newly added child records
before the data is committed?
I have a mapping of a one-many relationship using a foreign key. The detail
On Oct 11, 2010, at 7:50 AM, Sebastian Elsner wrote:
have one table called 'Assets' with a 'category' (String) and 'created'
(DateTime) column. Now I would like to find the records created since a given
datetime for each category:
This is what I thought would work (with a self-join):
On Oct 5, 2010, at 4:48 AM, Chris Withers wrote:
On 04/10/2010 13:16, Mark Erbaugh wrote:
If I were doing this in SQL, I would to the first command as
SELECT count(*)
FROM period
WHERE period.cycle = ?
Why would you do this first?
I wasn't sure why SA was issuing a select realperiod
I have a table described with:
BASE = declarative_base(name=APP_ID)
class Period(BASE):
__tablename__ = 'period'
realperiod = Column(Integer, primary_key=True)
cycle = Column(Integer)
[more columns]
I want to delete all records with a given value for the cycle column.
I'm trying to use a relationship that uses a set as the collection_class by
setting the collection_class parameter to set.
I chose a set since there should only be one instance corresponding to a give
table row since it is enforced by a foreign key on the many side.
When initially populating
On Oct 4, 2010, at 5:46 PM, Michael Bayer wrote:
On Oct 4, 2010, at 8:16 AM, Mark Erbaugh wrote:
I have a table described with:
BASE = declarative_base(name=APP_ID)
class Period(BASE):
__tablename__ = 'period'
realperiod = Column(Integer, primary_key=True
On Oct 4, 2010, at 8:30 PM, Michael Bayer wrote:
On Oct 4, 2010, at 8:06 PM, Mark Erbaugh wrote:
Thanks. What is the purpose of
SELECT period.realperiod AS period_realperiod
FROM period
WHERE period.cycle = ?
that appears to be generated by the session.query ... call
I have a self-referential table:
class L3Acct(BASE):
__tablename__ = 'l3_acct'
id = Column(Integer, primary_key=True)
parent = Column(ForeignKey('l3_acct.id'))
[]
When adding new rows to the table, the id field is not assigned a value until
the data is actually
On Sep 28, 2010, at 4:01 PM, Michael Bayer wrote:
On Sep 28, 2010, at 3:28 PM, Mark Erbaugh wrote:
I have a self-referential table:
class L3Acct(BASE):
__tablename__ = 'l3_acct'
id = Column(Integer, primary_key=True)
parent = Column(ForeignKey('l3_acct.id
If I retrieve data strictly for reporting or other read-only use, e.g. the
session will not be used to update data, should I expunge the objects returned
by the query from the session? If I just let the session object go out of
scope is that sufficient?
Thanks,
Mark
--
You received this
65 matches
Mail list logo