Re: [sqlalchemy] Tips for schema based db traversal and building

2015-09-08 Thread Mike Bayer
On 9/8/15 12:57 PM, Steve Murphy wrote: A bit difficult is grabbing just certain columns in the select, given that we have only a list of column names. That would be real nice if such a method were available in the core API. For example, a method for select whereby I could supply a simple lis

Re: [sqlalchemy] get_schema_names doesn't work with SQLite attached databases

2015-09-09 Thread Mike Bayer
On 9/9/15 4:59 PM, Van Klaveren, Brian N. wrote: Hi, I'm trying to find the attached databases of a SQLite database. I was expecting Inspector.get_schema_names to return something like: $ sqlite3 foo.db sqlite> create table a (a_id integer); sqlite3 bar.db sqlite> create table b (b_id inte

Re: [sqlalchemy] ORM: walk() related objects

2015-09-10 Thread Mike Bayer
On 9/10/15 8:48 AM, Pavel S wrote: Let's say, I have declarative classes A, B, C, D. A is the parent B has FK&relationship to A C has FK&relationship to B, D has FK&relationship to C etc... I'd like to implement _generic method_ walk(obj) which will recursively yield dependent/related object

Re: [sqlalchemy] ORM: walk() related objects

2015-09-10 Thread Mike Bayer
On 9/10/15 9:35 AM, Mike Bayer wrote: On 9/10/15 8:48 AM, Pavel S wrote: Let's say, I have declarative classes A, B, C, D. A is the parent B has FK&relationship to A C has FK&relationship to B, D has FK&relationship to C etc... I'd like to implement _generic method

Re: [sqlalchemy] ORM: walk() related objects

2015-09-10 Thread Mike Bayer
pop(0) to pop() here means we are doing depth-first instead of breadth-first. So. Some word that means "collection of things to operate upon"? I've seen "work" used. "buffer" ? eh. HTH, Ladislav Lenart On 10.9.2015 15:48, Mike Bayer wrote: On 9

Re: [sqlalchemy] ORM: walk() related objects

2015-09-10 Thread Mike Bayer
On 9/10/15 10:26 AM, Mike Bayer wrote: On 9/10/15 10:13 AM, Ladislav Lenart wrote: Hello. Just a really, really tiny and pedantic correction... The stack variable in the code is in fact a queue. This could potentially surprise some users / readers. To fix, please do one of the

Re: [sqlalchemy] SQLite objects getting closed in wrong thread, if session not explicitly closed

2015-09-11 Thread Mike Bayer
On 9/11/15 1:55 PM, Ben Sizer wrote: I'm using SQLAlchemy 1.0.8 with an SQLite file-based database, running as part of a Flask-based server, and getting some strange results. I'm seeing this exception raised: ProgrammingError: SQLite objects created in a thread can only be used in that

Re: [sqlalchemy] Re: polymorphic identity after_delete event

2015-09-15 Thread Mike Bayer
On 9/15/15 10:09 AM, Jakub Bąk wrote: I used before_delete and after_commit and it works like a charm. Thanks again! I have another problem related to this setup. I have a property defined on the Image model: | @property deffilename(self): return'{basename}.{extension}'.format(basename=sel

Re: [sqlalchemy] AttributeError: 'NoneType' object has no attribute 'accepts_scalar_loader'

2015-09-15 Thread Mike Bayer
On 9/15/15 1:02 PM, dewey wrote: I've got a SA session, and i'm running the following: cot = sess.query(MyTable).get( int(someIntAsString) ) I'm seeing the error: AttributeError: 'NoneType' object has no attribute 'accepts_scalar_loader' I'm guessing that means the record was not found.

Re: [sqlalchemy] Cast model id column from String to Integer

2015-09-15 Thread Mike Bayer
On 9/15/15 1:19 PM, Katie Wurman wrote: Hi, I'm having trouble implementing a model whose 'id' column needs to be cast to Integer type. Below is the implementation I've got so far: class CastToIntegerType(types.TypeDecorator): ''' Converts stored String values to Integer via CAST op

Re: [sqlalchemy] AttributeError: 'NoneType' object has no attribute 'accepts_scalar_loader'

2015-09-15 Thread Mike Bayer
On 9/15/15 2:05 PM, dewey wrote: The contents of the full traceback was: Traceback (most recent call last): File "/opt/paysys/python/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task R = retval = fun(*args, **kwargs) File "/opt/paysys/python/lib/python2.7/

Re: [sqlalchemy] Cast model id column from String to Integer

2015-09-15 Thread Mike Bayer
On 9/15/15 2:47 PM, Katie Wurman wrote: Ok thanks! Adding a bind_expression to my CastToInteger type ensures that when Person.id is included in a WHERE clause, the param is cast to varchar. This is ok, except now I have the following situation: class CastToIntegerType(types.TypeDecorator):

Re: [sqlalchemy] Cast model id column from String to Integer

2015-09-15 Thread Mike Bayer
On 9/15/15 4:10 PM, Mike Bayer wrote: On 9/15/15 2:47 PM, Katie Wurman wrote: class Person(Base): __tablename__ = 'person' id = Column('id_string', CastToIntegerType, primary_key=True) pets = relationship('Pets', primaryjoin='foreign(Pets.p

Re: [sqlalchemy] Expressions generated by select(...) changes when submitted in session.query

2015-09-15 Thread Mike Bayer
On 9/15/15 4:52 PM, Mourad Ben Cheikh wrote: Hi, I am using sqlalchemy in flask, essentially through flask-sqlalchemy, and my goal is to generate and execute queries on the fly. I am pretty new to sqlalchemy ( a great challenge and a great work) I am using a model generated by automap. The

Re: [sqlalchemy] Re: polymorphic identity after_delete event

2015-09-16 Thread Mike Bayer
On 9/16/15 5:28 AM, Jakub Bąk wrote: Thanks a lot! It works but I still have a problem. I want to make one query to get the root directory, all its children and the filenames of Image objects. My directory model looks like this: | classDirectory(Node): is_root =db.Column(db.Boolean,defau

Re: [sqlalchemy] There is any chance to SQLAlchemy works with syncio?

2015-09-16 Thread Mike Bayer
On 9/16/15 10:17 AM, Johnny W. Santos wrote: Hi guys, I would like to know if theres is any chances to SQLAlchemy support asyncio out of the box? Like the ORM and such. Well the "real" answer is "yes", which is that you'd put your ORM business logic in a threadpool using https://docs.pyth

Re: [sqlalchemy] Mixed data type for a column

2015-09-16 Thread Mike Bayer
On 9/16/15 6:46 AM, Mattias Lagergren wrote: The important part is the casting inside of the case expression: | dynamic_cast=sqlalchemy.sql.expression.case( [ ( variable_register.c.type =='number', sqlalchemy.cast(variable_value.c.value,types.Numeric)

Re: [sqlalchemy] Cast model id column from String to Integer

2015-09-16 Thread Mike Bayer
OK, new day, new perspectives. This is the best way to do the mapping / type: class CastToIntegerType(TypeDecorator): impl = String def column_expression(self, col): return cast(col, Integer) def process_bind_param(self, value, dialect): return str(value) class P

Re: [sqlalchemy] migrating from backref to back_populates -- advice?

2015-09-16 Thread Mike Bayer
maybe you can run through all the mappings with a script and produce a textfile indicating the settings for all the relationships. then you can verify that the back_populates code change produces the same thing. On 9/16/15 3:47 PM, Jonathan Vanasco wrote: I'm about to migrate about 70 relati

Re: [sqlalchemy] most correct way to get the columns in an object?

2015-09-16 Thread Mike Bayer
On 9/16/15 4:30 PM, Jonathan Vanasco wrote: given the object `source`, these both work cols = [c.key for c in list(source.__table__.columns)] cols = [c.name for c in sqlalchemy.orm.class_mapper(source.__class__).mapped_table.c] I'm sure there are other ways. is ther

Re: [sqlalchemy] possible bug/docs deficiency on classes with multiple identical relationships

2015-09-16 Thread Mike Bayer
On 9/16/15 5:49 PM, Jonathan Vanasco wrote: This drove me crazy for an hour today, until I finally figured out what was going on. I have a class with a few relationships: class Foo(base): # relationships have a prefix that describe the relation l_ (list) or o_ (scalar)

Re: [sqlalchemy] AttributeError: 'NoneType' object has no attribute 'accepts_scalar_loader'

2015-09-16 Thread Mike Bayer
check out this case, this is one way to reproduce that: https://bitbucket.org/zzzeek/sqlalchemy/issues/3532/detect-property-being-assigned-to-more On 9/15/15 3:56 PM, dewey wrote: I'll see if I can reproduce this in a simple example.it's currently in a job being run every night from a Cel

Re: [sqlalchemy] AttributeError: 'NoneType' object has no attribute 'accepts_scalar_loader'

2015-09-17 Thread Mike Bayer
On 9/16/15 8:05 PM, dewey wrote: Hey Mike, I've found and fixed (with help) my problem, but I thought I'd describe it here to support anyone else who hits this... Was not a threading issue..it was a combination of: * data-edge case * bug in our code * bug in how SA was reporting a

Re: [sqlalchemy] Capturing query parameters

2015-09-18 Thread Mike Bayer
On 9/18/15 3:22 PM, George Reilly wrote: I find [SQLTap](http://sqltap.inconshreveable.com/) invaluable for profiling SQLAlchemy queries. Currently, I've reduced one operation in our system from nearly 12,000 queries to 800, and I'm not finished yet. SQLTap listens for the before_execute and

Re: [sqlalchemy] Capturing query parameters

2015-09-19 Thread Mike Bayer
On 9/18/15 7:58 PM, George Reilly wrote: Thanks for the prompt answer. I tried after_cursor_execute, but it didn't really help as I just got a tuple of the values, without a clear way to associate them with the parameter names. Ultimately, I found that the following gives me the best result

Re: [sqlalchemy] create and update table dynamically in declarative base

2015-09-19 Thread Mike Bayer
On 9/17/15 5:11 PM, Nana Okyere wrote: So I have a form that will collect the name attribute of TableInfo. Now, how do I dynamically - in runtime- create an empty table with the name attribute given? I'm not sure what this is asking. An "empty" table is this: t = Table('mytable', metadat

Re: [sqlalchemy] how to find none-referenced objects

2015-09-21 Thread Mike Bayer
On 9/20/15 8:05 AM, c.bu...@posteo.jp wrote: Instances of 'A' can have many references to instances of 'B'. I want to find all 'B' instances that are not referenced by an 'A'. I am not sure if this is possible with SQLAlchemy-Query. And I am not sure if the backref() part in the code is needed

Re: [sqlalchemy] Dynamic Declarative Class Generation and "TypeError: Boolean value of this clause is not defined" when doing help()

2015-09-21 Thread Mike Bayer
On 9/21/15 4:08 PM, Cliff Hill wrote: So, I have some code that is constructing a declarative table definition on the fly, built from a YAML file. It works great. However, when I try to do *help(tablename)*, I get the following error: Python 3.4.3 (default, May 14 2015, 09:48:44) [GC

Re: [sqlalchemy] Encapsulate multiple columns into one

2015-09-22 Thread Mike Bayer
On 9/22/15 7:18 AM, Yegor Roganov wrote: I know that I can encapsulate multiple columns into one using either composite column or hybrid_property, but unfortunatelly neither suits me 100%. Let's say I have a `File` model which includes fields `id`, 'file_name`, `storage_type`, and there is

Re: [sqlalchemy] has anyone used/abused events to reflect db changes on cached orm objects?

2015-09-22 Thread Mike Bayer
On 9/22/15 1:52 PM, Jonathan Vanasco wrote: This is, admittedly, an abuse of SqlAlchemy. I'm wondering if anyone else has dealt with this situation before and how they handled it. We have a handful of situations where SqlAlchemy generates a raw sql update against a table. Something like

Re: [sqlalchemy] loading of relationships

2015-09-24 Thread Mike Bayer
On 9/24/15 9:32 AM, Julien Cigar wrote: Hello, I'm using SQLAlchemy 1.0.8 with joinedload inheritance. On one of the Child I have a relationship property and I wondered if there is an easy way to innerjoin=True this relation only in a non-polymorphic context ? In my case I have the base class

Re: [sqlalchemy] "No such event 'instrument_class' for target" for mixin that needs to listen to 'instrument_class'

2015-09-24 Thread Mike Bayer
On 9/24/15 2:06 PM, Chris Withers wrote: Hi All, I have a mixin class here that I've factored out of one project as I want to use it in another one: https://github.com/Mortar/mortar_mixins/blob/master/mortar_mixins/temporal.py The problem is that importing the module seems to result in the

Re: [sqlalchemy] Storing data on an instance that's deleted when the object is expired

2015-09-25 Thread Mike Bayer
On 9/25/15 8:22 AM, Adrian wrote: For some methods/properties on a model it might be useful to memoize its result. There are some common decoratos such as cached_property from werkzeug which simply add the value to the object's __dict__ after retrieving it the first time (thus not calling the

Re: [sqlalchemy] funky session usage to add join conditions and where clauses

2015-09-25 Thread Mike Bayer
On 9/25/15 4:18 AM, Chris Withers wrote: Hi All, Suppose I have the following: from sqlalchemyimport Column, Integer, Text, ForeignKey, and_ from sqlalchemy.dialects.postgresqlimport TSRANGEas Range from sqlalchemy.ext.declarativeimport declarative_base Base = declarative_base() class A(Bas

Re: [sqlalchemy] views

2015-09-25 Thread Mike Bayer
On 9/25/15 3:13 AM, Chris Withers wrote: Hi All, Is this still the best way to hand views, or are there later and greater things in 1.0+? https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/Views How would I make a view behave like a normal declarative class (column attributes, etc)

Re: [sqlalchemy] how to dynamically work with an aliased table?

2015-09-25 Thread Mike Bayer
On 9/25/15 2:41 AM, David Allouche wrote: On 24 Sep 2015, at 17:38, Jonathan Vanasco > wrote: On Thursday, September 24, 2015 at 3:05:56 AM UTC-4, David Allouche wrote: That looks like the right approach. There is probably something else in your act

Re: [sqlalchemy] views

2015-09-25 Thread Mike Bayer
On 9/25/15 5:26 AM, Chris Withers wrote: Also forgot to ask... What's support like in Alembic for creating views (especially if the views are described by a declarative class as I'm looking for below...) the trick with views is migrating them when the tables change without lots of repetiti

Re: [sqlalchemy] ora-25408 can not safely replay call

2015-09-26 Thread Mike Bayer
On 9/26/15 10:28 AM, Abhishek Sharma wrote: Hi Team, We have integrated our Django project with sqlalchemy ORM. Django: 1.4.2 SQLALCHEMY-0.8 Recently we started getting the following error while making the service call and it leads to internal server error: *ora-25408 can not s

Re: [sqlalchemy] DB sync on application level

2015-09-26 Thread Mike Bayer
On 9/26/15 6:35 AM, Cornelinux K wrote: Hello, I have an application that uses an SQL database with also many write access. Now I am thinking of high availability. One solution was to set up a mysql master master replication. that's a good solution. But I was thinking, there might be so

Re: [sqlalchemy] funky session usage to add join conditions and where clauses

2015-09-26 Thread Mike Bayer
On 9/25/15 12:24 PM, Chris Withers wrote: On 25/09/2015 13:58, Mike Bayer wrote: session.query(A).filter(A.id>10).as_at(now)) you'd need to subclass Query and dig into Query.column_descriptions to get at the existing entities, then add all that criterion. remind me where the docs

Re: [sqlalchemy] views

2015-09-26 Thread Mike Bayer
On 9/25/15 9:00 AM, Mike Bayer wrote: On 9/25/15 3:13 AM, Chris Withers wrote: Hi All, Is this still the best way to hand views, or are there later and greater things in 1.0+? https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/Views How would I make a view behave like a normal

Re: [sqlalchemy] DB sync on application level

2015-09-27 Thread Mike Bayer
On 9/27/15 5:17 PM, Cornelinux K wrote: Hi Michael, thanks for your response. At least it shows me, that obviously this seems to be no common idea - mostly known as a bad idea. I do not want to sync anything on a database level, but on a logical level. It is not important, that entries hav

Re: [sqlalchemy] Please advice with new oracle 'OFFSET x ROWS FETCH NEXT x ROWS' approach in 12c

2015-09-29 Thread Mike Bayer
On 9/29/15 9:50 AM, Ralph Heinkel wrote: Hi everybody, oracle 12c has received the long awaited possibility to properly provide LIMIT and OFFSET parameters to a select query. See https://oracle-base.com/articles/12c/row-limiting-clause-for-top-n-queries-12cr1 for details. wow! In short

Re: [sqlalchemy] Handle multiple relations between two rows/objects

2015-09-29 Thread Mike Bayer
On 9/29/15 7:20 AM, c.bu...@posteo.jp wrote: This is related to this post I found this problem in my application using Python3 with a SQLAlchemy connected sqlite-database. Simple des

Re: [sqlalchemy] Tips for schema based db traversal and building

2015-09-30 Thread Mike Bayer
On 9/30/15 3:09 PM, Steve Murphy wrote: See below On Tuesday, September 8, 2015 at 9:00:12 PM UTC-4, Michael Bayer wrote: you can get these like this: from sqlalchemy import inspect insp = inspect(my_engine) fk_constraints = insp.get_foreign_keys('mytable') uq_constr

Re: [sqlalchemy] Tips for schema based db traversal and building

2015-10-01 Thread Mike Bayer
On 10/1/15 12:33 AM, Steve Murphy wrote: On Wednesday, September 30, 2015 at 1:43:46 PM UTC-6, Michael Bayer wrote: there's no known bugs in fetching unique constraints. PG 8.4 is a pretty old version but should be working. note that a unique index and a unique constraint are

Re: [sqlalchemy] Bulk inserting rows into a dynamically created table.

2015-10-01 Thread Mike Bayer
I would definitely not rely upon new Oracle features like GENERATED AS IDENTITY unless it is absolutely no issue. The SQL you may emit for using NEXTVAL is along the lines of: INSERT INTO table (id, col1, col2, ...) VALUES (my_sequence.nextval, 'data1', 'data2', ...) See the example at http

Re: [sqlalchemy] Postgres' arrays in subqueries

2015-10-01 Thread Mike Bayer
On 10/1/15 4:35 AM, artee wrote: Mike and others :) I have the following sql: select models.code, *array*( select *(clients.id, clients.code) *from clients group by clients.id, clients.code ) as envs from models I ended with something like this: items = DBSession.query(Cli

Re: [sqlalchemy] unregister Tables from Metadata

2015-10-01 Thread Mike Bayer
On 10/1/15 5:56 AM, Pavel S wrote: Hi, we use application-level partitioning (but no real partitioning in mysqld), where new tables are created daily with the same structure, but different name (suffix). * mysqld is shared for these components: * daemon written in C++ o creates

Re: [sqlalchemy] Is there a better and more idiomatic way to accomplish this?

2015-10-01 Thread Mike Bayer
On 10/1/15 11:41 AM, Massimiliano della Rovere wrote: Greetings, I have two questions to the following code that works, but looks dirty to me. Being new to SQLAlchemy I'd like to ask for advices. The database is PostgreSQL. The following check_xyz function must check whether the index "tabl

Re: [sqlalchemy] lowercase identifiers in Oracle

2015-10-02 Thread Mike Bayer
On 10/2/15 9:44 AM, Massimiliano della Rovere wrote: cx-Oracle==5.2 SQLAlchemy==1.0.8 I'm in the weird situation of dealing with an Oracle database with lowercase identifiers (they were created by another software that escapes always table/schema/index identifiers). I get a "NoSuchTableErr

Re: [sqlalchemy] correlate() with aliases having no effect on FROM clause in 1.0.8?

2015-10-02 Thread Mike Bayer
On 9/29/15 8:47 PM, Charles Duffy wrote: From a StackOverflow answer describing use of the correlate() call in SQLALchemy, at http://stackoverflow.com/questions/13056049/how-to-specify-the-from-tables-in-sqlalchemy-subqueries: |>>>printstr(q1)SELECT t3.id AS t3_id FROM tbl AS t3,tbl AS t1

Re: [sqlalchemy] lowercase identifiers in Oracle

2015-10-05 Thread Mike Bayer
On 10/5/15 5:21 AM, Massimiliano della Rovere wrote: The quoted_name tracebacks (i.e. is not enough) with at FOREIGN KEYS, probably with other constructs too. # this works fine Table( quoted_name("x", quote=True), metadata, schema=schemaname, autoload=True, extend_existing=True

Re: [sqlalchemy] lowercase identifiers in Oracle

2015-10-05 Thread Mike Bayer
On 10/5/15 9:28 AM, Massimiliano della Rovere wrote: I've found a solution to the reflect problem, but, given my limited knowledge of SQLAlchemy, I do not know how it performs and whether there is better one. that was the workaround I was going to suggest, so stick with that until 1.0.9 com

Re: [sqlalchemy] Unexpected missing join when using joined table inheritance

2015-10-05 Thread Mike Bayer
On 10/5/15 2:51 PM, Will Angenent wrote: I have run into an interesting condition when using joined table inheritance. For example we have the typical employee, manager and engineer tables with the following relationships: - an engineer is an employee - a manager is an employee - an employee

Re: [sqlalchemy] Re: ora-25408 can not safely replay call

2015-10-05 Thread Mike Bayer
I'm not familiar with the ORA-25408 error or what causes it. You might want to check on the cx_oracle mailing list. On 10/5/15 2:32 PM, Abhishek Sharma wrote: Team can someone help us to resolve this issue. I am not sure whether due to this issue my apache process got hanged and need to re

Re: [sqlalchemy] Re: SQLAlchemy under Jython fails with Maximum Recursion Depth Exceeded

2015-10-06 Thread Mike Bayer
SQLAlchemy is not supporting Jython right now - the interpreter invariably has too many issues for us to constantly keep chasing them down. On 10/6/15 1:36 PM, Michael Naber wrote: > It could be due to this: > http://sourceforge.net/p/jython/mailman/message/34131065/ > > On Tue, Oct 6, 2015 at 11

Re: [sqlalchemy] Bulk inserting rows into a dynamically created table.

2015-10-06 Thread Mike Bayer
Have you looked through the general techniques of creating Table objects at http://docs.sqlalchemy.org/en/rel_1_0/core/metadata.html? If you have a list of attribute names, you can programmatically create a Table object from that. On 10/6/15 10:39 AM, Nana Okyere wrote: > Any take on this? I re

Re: [sqlalchemy] Bulk inserting rows into a dynamically created table.

2015-10-06 Thread Mike Bayer
On 10/6/15 3:48 PM, Nana Okyere wrote: > Mike, > > The table creation part is done. My question is about how to insert > rows/data into a table that is dynamically created. This dynamically > created table is not represented by a class or anything in sqlalchemy. if the table is there you can just

Re: [sqlalchemy] getting the identity for objects not in a session

2015-10-08 Thread Mike Bayer
On 10/8/15 12:47 PM, Chris Withers wrote: > Hi All, > > Reading > http://docs.sqlalchemy.org/en/rel_1_0/orm/internals.html?highlight=identitymap#sqlalchemy.orm.state.InstanceState.identity > I can understand why a new object not in a session won't have an > identity. > > However, that had me wond

Re: [sqlalchemy] pgsql + jsonb + orm update = possible bug?

2015-10-09 Thread Mike Bayer
On 10/9/15 8:33 AM, Richard Gerd Kuesters wrote: > Hello! I was working with a JSONB column in postgres and I noticed > that no updates were issued when changing some inside value, so I have > to issue "*flag_modified*" everytime I change my JSONB attribute. > Here's a sample code that shows this

Re: [sqlalchemy] UniqueObject recipe with tables containing relationships and optional columns

2015-10-09 Thread Mike Bayer
On 10/7/15 5:21 PM, Marten Jakobsen wrote: > Hi, > > I'm using the UniqueObject recipe [1] for simple two column tables > and it works just fine, but what is the best way to use it with tables > containing relationships? > > I usually did: > > > mytime = Timestamp.as_unique(session, timestamp=val

Re: [sqlalchemy] Proper syntax for __table_args__ ?

2015-10-13 Thread Mike Bayer
On 10/13/15 7:16 AM, Don O'Hara wrote: > I'm looking for advice on best SA coding practices to accomplish: > > 1. Use bind keys I'm not familiar with that, I see you using something called __bind_key__ and SQLALCHEMY_BINDS. These are not constructs that are part of SQLAlchemy; if this is a thi

Re: [sqlalchemy] Exception in logger while using query options

2015-10-14 Thread Mike Bayer
On 10/14/15 5:34 AM, Ofir Herzas wrote: > An exception pertaining to the logger is raised when using query.options > > Here is the relevant part of the exception: issue 3539 fixed for 1.0.9: https://bitbucket.org/zzzeek/sqlalchemy/issues/3539 > > > query = query.options(sqlalchemy.orm

Re: [sqlalchemy] running parallel migrations using sharded/partioned/spaced queries?

2015-10-14 Thread Mike Bayer
On 10/14/15 12:55 PM, jason kirtland wrote: > If you can partition the rows numerically, this is trivially easily to > implement using redis as the orchestrator. > > For example if you have integer PKs, you might have a loop like: > > offset = 0 > while offset < tablesize: > for

[sqlalchemy] Alembic 0.8.3 Released

2015-10-16 Thread Mike Bayer
Alembic 0.8.3 is now available. This is a bugfix release that repairs a few issues, including in the areas of autogenerate and batch mode. Changes for 0.8.3 are available at: http://alembic.readthedocs.org/en/latest/changelog.html#change-0.8.3 Download Alembic 0.8.3 at Pypi at: https://pypi.pyth

Re: [sqlalchemy] Re: executemany() incorrectly used for updates to a table with row versioning with psycopg2

2015-10-19 Thread Mike Bayer
On 10/19/15 11:44 AM, Steven Winfield wrote: > The problem seems to be that the result set from an executemany() call > in psycopg2 is discarded - here is a good stackoverflow article on this > subject: > http://stackoverflow.com/questions/21624844/getting-ids-of-multiple-rows-inserted-in-psycopg

Re: [sqlalchemy] Re: executemany() incorrectly used for updates to a table with row versioning with psycopg2

2015-10-19 Thread Mike Bayer
On 10/19/15 11:57 AM, Mike Bayer wrote: > > > On 10/19/15 11:44 AM, Steven Winfield wrote: >> The problem seems to be that the result set from an executemany() call >> in psycopg2 is discarded - here is a good stackoverflow article on this >> subject: >> h

Re: [sqlalchemy] add_column migration with column enum error

2015-10-19 Thread Mike Bayer
On 10/19/15 3:39 PM, m1yag1 wrote: > I have the following in my upgrade function of the revision file: > > | > | > > defupgrade(): > op.add_column('gates_experiment_users', > sa.Column('experiment_group', > postgresql.ENUM('Control', >

[sqlalchemy] SQLAlchemy 1.0.9 Released

2015-10-20 Thread Mike Bayer
SQLAlchemy release 1.0.9 is now available. Release 1.0.9 is a bugfix release, pushing out a collection of mostly small fixes that have accumulated over the past few months. In particular there is one small but important fix for users of the latest cx_Oracle library (5.2 or greater) in conjunctio

Re: [sqlalchemy] Performance questions on semi-large result sets

2015-10-21 Thread Mike Bayer
On 10/21/15 4:52 PM, Uri Okrent wrote: > Hello, I'm trying to understand the various performance implications of > working with the ORM layer, vs the SQL language layer, vs a raw dbapi > connection. Ideally, I would like to stick with the ORM layer > > First, the set up: > CentOS 6 > SQLAlchemy

Re: [sqlalchemy] Performance questions on semi-large result sets

2015-10-21 Thread Mike Bayer
On 10/21/15 7:27 PM, Uri Okrent wrote: > Interesting... > > On Wednesday, October 21, 2015 at 5:43:22 PM UTC-4, Michael Bayer wrote: > > class Customer(Base): > __tablename__ = "customer" > id = Column(Integer, primary_key=True) > name = Column(Unicode(255)) >

Re: [sqlalchemy] Multiple aliases not aliased correctly

2015-10-21 Thread Mike Bayer
On 10/21/15 9:19 PM, Kristi Tsukida wrote: > It looks like only one aliased table gets aliased correctly when joining > to multiple aliased tables. > > Test case: > > from __future__ import print_function > from sqlalchemy import Integer, String, select, Date, and_ > from sqlalchemy import Co

Re: [sqlalchemy] Erratic behaviour with relationship primaryjoin using bindparam

2015-10-22 Thread Mike Bayer
On 10/22/15 7:22 AM, ch...@lystable.com wrote: > Hi, > > I've been trying to unravel some spaghetti code by using bindparams in > relationships, which at first seemed like a neat solution to my > problems. Unfortunately, it seems to have some behaviour that I find > erratic or unpredictable. I'm

Re: [sqlalchemy] Erratic behaviour with relationship primaryjoin using bindparam

2015-10-23 Thread Mike Bayer
On 10/23/15 5:41 AM, ch...@lystable.com wrote: > > > On Thursday, October 22, 2015 at 2:57:32 PM UTC+1, Michael Bayer wrote: > > > > On 10/22/15 7:22 AM, ch...@lystable.com wrote: > > Hi, > > > > I've been trying to unravel some spaghetti code by using > bindparams in >

Re: [sqlalchemy] Dinamically adding an outer join to an existing select

2015-10-24 Thread Mike Bayer
On 10/24/15 4:19 PM, Lele Gaifax wrote: > Hi all, > > I'd like to learn a trick that would allow me to don't-repeat-myself: in my > current project, I have the noble goal of replacing MySQL with PostgreSQL. As > this is obviously an on-going effort, I need to keep existing code in working > orde

Re: [sqlalchemy] Is table reflection thread safe?

2015-10-25 Thread Mike Bayer
On 10/25/15 3:37 AM, peon ma wrote: > Hello > > I have a problem with table reflection under multi-thread without lock. > It works fine under single-thread or multi thread with lock protection. > > I got following result by the attached test script: > single-thread or multi thread with lock pro

Re: [sqlalchemy] TypeDecorator odd behavior

2015-10-28 Thread Mike Bayer
On 10/27/15 9:01 PM, Uri Okrent wrote: > Hello, I've created a TypeDecorator for use with postgresql's JSON type, > for the purpose of adapting it to sqlite and it's producing an incorrect > bind parameter when using JSON's column index operation. > > I'm using sqlalchemy 0.9.4 (I haven't been

Re: [sqlalchemy] Relationships not being set to None when related object is deleted

2015-10-28 Thread Mike Bayer
On 10/28/15 10:42 AM, Chris Wilson wrote: > Hi all, > > I'm having problems with relationships getting out of sync with the > underlying foreign key properties, and hoping that someone can help. > > It seems from the manual (if I've understood correctly), that deleting > one side of a relations

Re: [sqlalchemy] Relationships not being set to None when related object is deleted

2015-10-28 Thread Mike Bayer
On 10/28/15 1:26 PM, Chris Wilson wrote: > OK, I hadn't thought of that, it might work but in fact I want to delete > a Cat when it has no Houses left (House -> Cat in this case, with > uselist=True instead of uselist=False as in the example above) and it's > not clear that delete-orphan can reli

Re: [sqlalchemy] Percona Server

2015-10-28 Thread Mike Bayer
On 10/28/15 1:45 PM, Sean Harrington wrote: > Has anybody tried to use SQLAlchemy on Percona Server? yes Percona Server is > a "drop-in replacement" for MySQL with InnoDB optimizations -- however > it contains additional INFORMATION_SCHEMA tables, and performance > tables...Want to make sure

Re: [sqlalchemy] Created edge-case bug with `contains_eager`, can't reproduce

2015-10-29 Thread Mike Bayer
On 10/29/15 6:50 PM, Jonathan Vanasco wrote: > I've spent an hour trying to reproduce this bug and can't. I'm hoping > someone can suggest what might be going on so I can make this > reproducable for a bug report > > I have 2 classes: > > class Foo(Base): > __tablename__ = 'foo' >

Re: [sqlalchemy] Created edge-case bug with `contains_eager`, can't reproduce

2015-10-30 Thread Mike Bayer
On 10/29/15 7:54 PM, Jonathan Vanasco wrote: > > > The difference is between these 2 forms: > > [(f.id, f.bar_id) for f in > session.query(Foo).options(joinedload('bar')).order_by(Foo.id.desc()).offset(0).limit(100).all()] > [(f.id, f.bar_id) for f in > session.query(Foo).options(contains_eage

Re: [sqlalchemy] sqlalchemy.exc.operationalerror: (cx_oracle.operationalerror) ora-03114: not connected to oracle

2015-10-31 Thread Mike Bayer
On 10/31/15 2:44 AM, Nana Okyere wrote: > New to python, web development and hence flask. I have a small > application that accepts excel inputs, extracts the data and writes it > out oracle. My stack includes flask-sqlalchemy, cx_oracle. When I upload > a small excel file with about 10 K rows, i

Re: [sqlalchemy] Re: Temporarily drop and re-create constraint

2015-10-31 Thread Mike Bayer
On 10/31/15 5:48 PM, r...@rosenfeld.to wrote: > On Friday, October 30, 2015 at 6:02:47 PM UTC-5, r...@rosenfeld.to wrote: > > I would like to temporarily drop a foreign key constraint while > loading data and then revert the constraint's removal when done. > I'm hoping to do this w

Re: [sqlalchemy] returned_defaults fails after upgrading from 0.9.4

2015-10-31 Thread Mike Bayer
this is likely http://docs.sqlalchemy.org/en/rel_1_0/changelog/migration_10.html#the-insert-from-select-construct-now-implies-inline-true - use explicit returning(). returned_defaults implies only a single row INSERT which is not the case for INSERT from SELECT. On 11/01/2015 01:29 AM, gbr wro

Re: [sqlalchemy] column_property with load_only and inheritance

2015-11-02 Thread Mike Bayer
On 11/02/2015 09:16 AM, Mattias Lagergren wrote: > Hi, > > I'm trying to use load_only and joinedload on a relationship > model.Asset.parent. The parent relation is polymorphic and can be either > Task or Project with the common Base class called Context. > > | > importsqlalchemy.orm >

Re: [sqlalchemy] compare a object/instance against its data in the database

2015-11-03 Thread Mike Bayer
On 11/03/2015 03:21 PM, c.bu...@posteo.jp wrote: Is there a way to find out if a persistent sqlalchemy mapped object was modified? It means I recieve a object (persistent, with identiy) from the database. Then the user (maybe!) modify its data in a dialog-window. obj = session.query(MyClas

Re: [sqlalchemy] SQLAlchemy: Database Access Using Python - Developer's Library book

2015-11-05 Thread Mike Bayer
On 11/03/2015 06:55 PM, Ken Lareau wrote: I came across this during a search, and in the four different sites I've checked, I've seen four different release dates varying from 2008 to 2018, for example: http://www.amazon.com/SQLAlchemy-Database-Access-Developers-Library/dp/0132364670 (which h

Re: [sqlalchemy] Re: column_property with load_only and inheritance

2015-11-05 Thread Mike Bayer
On 11/03/2015 07:32 AM, Mattias Lagergren wrote: Hi Michael, I've been putting together a self-contained example. If you save it to a file test_model you should be able to run it: what's the SQL output with echo=True on the engine? is the subquery for context rendered in the SQL and is it

Re: [sqlalchemy] Filter on relationships

2015-11-07 Thread Mike Bayer
On 11/07/2015 09:42 AM, Casper Eekhof wrote: > Dear community, > I was stuck with this issue and although I found a workaround for it, > I'm really curious if there is a solution for it in SQLAlchemy. I've > posted this question before, but on Stack Overflow >

Re: [sqlalchemy] can't read CLOB columns

2015-11-08 Thread Mike Bayer
On 11/08/2015 05:58 AM, Ofir Herzas wrote: > Sqlalchemy 1.0.6 > > Trying to issue a simple select on a CLOB column, throws the following > exception: > > | > Traceback(most recent call last): > File"/opt/5.3/server/handlers/orm.py",line 81,inselect > > result =query.all() > > File"/opt

Re: [sqlalchemy] inherited column_property

2015-11-09 Thread Mike Bayer
On 11/09/2015 01:17 PM, Uri Okrent wrote: > I'm trying to define a column_property on a mixin class for a > joined-table polymorphic class but I'm having issues with the from/joins. > > These are my classes: > > | > classMomBase(Base): > __tablename__ ='mom_objects' > guid =Column(Text,

Re: [sqlalchemy] Updates in after_flush_postexec

2015-11-09 Thread Mike Bayer
On 11/09/2015 03:10 PM, Patrick Lewis wrote: > I have a sample gist that makes a change to an object in the > after_flush_postexec event. > > https://gist.github.com/p-lewis/deb498bdfb6172bf0013 > > SQLAlchemy==1.0.9 > > > As I read the documentation >

Re: [sqlalchemy] How do a I create Postgres Materialized View using SQLAlchemy?

2015-11-09 Thread Mike Bayer
On 11/09/2015 03:52 PM, Jeff Widman wrote: > A couple of quick questions about Postgres Materialized Views--searched, > but found very little: > > I've got a few values that are fairly expensive to calculate, so I'd > like to pre-calculate the results. It's fine if the the data is stale > for a

Re: [sqlalchemy] best mysql dialect?

2015-11-13 Thread Mike Bayer
python-mysql was forked as mysqlclient-python: https://github.com/PyMySQL/mysqlclient-python if you want pure Python use PyMySQL by the same author. On 11/13/2015 08:33 AM, Chris Withers wrote: > Hello, > > What's the best mysql dialect to use nowadays? > > python-python aka mysqldb used t

Re: [sqlalchemy] Collection mapper to group by relationship

2015-11-15 Thread Mike Bayer
On 11/15/2015 06:44 PM, Fabian Freyer wrote: > Hi, > > I am trying to do some ugly schemaception. A semi-working minimal > example is at > https://gist.github.com/fabianfreyer/f92054d260dc0485c649#file-field_storage-py. > > The data model I am implementing is hierarchical, fieldable containers.

Re: [sqlalchemy] How do a I create Postgres Materialized View using SQLAlchemy?

2015-11-16 Thread Mike Bayer
hat just calls upon CreateView create and CreateViewIndex directly. > > More than happy to submit a PR helping tidy up the docs on this, just > not sure what I should be saying. well we'd have to see what we get at the end and if it looks usable or not. I guess this would all be

Re: [sqlalchemy] Best way to use SERIALIZABLE READ ONLY DEFERRABLE transaction with the ORM?

2015-11-17 Thread Mike Bayer
On 11/16/2015 07:38 AM, Donald Stufft wrote: > I am currently using the SQLAlchemy ORM and I'd like to be able to start > up transactions using PostgreSQL's SERIALIZABLE READ ONLY DEFERRABLE > isolation level. I don't want every single transaction to use this > isolation level nor do I have the a

Re: [sqlalchemy] Adding a condition to an aliased subquery generates a Cartesian product (and incorrect results)

2015-11-19 Thread Mike Bayer
On 11/19/2015 12:38 AM, Laura Pearlman wrote: > Hi, > > When I do this in Python: > > metadata = MetaData() > person = Table('person', metadata, Column('name', String), Column('id', > Integer)) > base_query = select(person.c).alias('person_alias').select() > query = base_query.where(base_query.

<    1   2   3   4   5   6   7   8   9   10   >