Re: [sqlalchemy] How to have MySQL store TIMESTAMP but return timezone-aware datetime objects

2019-06-27 Thread Mike Bayer
On Thu, Jun 27, 2019, at 12:02 PM, Charles-Axel Dein wrote: > Hi, > > I'm trying to have a deleted_at column on my records. I use MySQL and latest > sqlalchemy as of writing. For historical reasons, I want to keep using the > MySQL's TIMESTAMP columns. > > I would like to use timezone-aware

Re: [sqlalchemy] Listing all the tables that a query uses

2019-06-26 Thread Mike Bayer
On Wed, Jun 26, 2019, at 1:51 PM, Brian Maissy wrote: > Background: I have a bunch of materialized views (postgres) that are > dependent on each other. When I want to change one of them, I drop cascade it > (postgres does not provide a way to modify the query of an existing > materialized

Re: [sqlalchemy] primaryjoin and remote/foreign sides

2019-06-25 Thread Mike Bayer
t SQLAlchemy is supposed to do :) that's a really big query though :) > > On Fri, Jun 21, 2019 at 02:32:36AM -0700, Julien Cigar wrote: > > > > > > On Thursday, June 20, 2019 at 4:24:14 PM UTC+2, Mike Bayer wrote: > > > > &g

Re: [sqlalchemy] Re: How to connect to Amazon Redshift and Presto using SQLAlchemy?

2019-06-25 Thread Mike Bayer
please communicate with the sqlalchemy-redshift folks at https://github.com/sqlalchemy-redshift/sqlalchemy-redshift/issues as I know nothing about what special options it offers On Tue, Jun 25, 2019, at 10:30 PM, Preutti Puawade wrote: > Hi, > > When I set engine as below, > > engine = >

Re: [sqlalchemy] Where clause when using polymorphic_identity on base class

2019-06-25 Thread Mike Bayer
On Fri, Jun 21, 2019, at 7:22 AM, Dmytro Starosud wrote: > Base class `A1` contains `polymorphic_identity` (along with > `polymorphic_on`), but `Query(A1)`doesn't produce where clause, whereas > `Query(A2)` (where `A2` is subclass of `A1` with its own > `polymorphic_identity`) does. > Tried

Re: [sqlalchemy] Primary keys mandatory sortability

2019-06-24 Thread Mike Bayer
On Mon, Jun 24, 2019, at 1:24 PM, Nico C. wrote: > One of the many reasons not to implement __lt__, is that the types are used > with different databases. Those have had very different stories, especially > enum labels may not have been added in the same order. Hence, defining and > order may

Re: [sqlalchemy] Primaire keys mandatory sortability

2019-06-24 Thread Mike Bayer
On Mon, Jun 24, 2019, at 6:12 AM, Nico C. wrote: > Hi there, > > Where I work, in our data model, we'd have several the opportunity to have > primary keys defined has a composite of something + an enum value. Though > because sqlalchemy requises > that primary keys can be sorted, it is not

Re: [sqlalchemy] How to connect to Amazon Redshift and Presto using SQLAlchemy?

2019-06-24 Thread Mike Bayer
On Mon, Jun 24, 2019, at 3:33 AM, Preutti Puawade wrote: > Hi there, > > It could be a non-sense question for you but for I've struggling on this for > weeks and search result from google cannot help so I'm end up here. > > Normally I've use SQL client program as SQLwokbench/J and it's using

Re: [sqlalchemy] How to inspect filters

2019-06-23 Thread Mike Bayer
On Sun, Jun 23, 2019, at 5:45 PM, Andrew Martin wrote: > I have a generic CRUDService for my web app. It's a pattern that was loosely > suggested to me by Mike a while back. I've probably not implemented it the > way he intended, but it works pretty well in a pretty small amount of code. > >

Re: [sqlalchemy] Masking SAWarning: Flushing object ... with incompatible polymorphic identity

2019-06-21 Thread Mike Bayer
On Fri, Jun 21, 2019, at 2:14 AM, Chris Withers wrote: > On 20/06/2019 16:00, Mike Bayer wrote: > > > >> On Thu, Jun 20, 2019, at 3:14 AM, Chris Withers wrote: > >>> Hi All, > >>> > >>> I'm getting this warning: > >>> >

Re: [sqlalchemy] sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) operator does not exist: jsonb = uuid",

2019-06-20 Thread Mike Bayer
you probably want to use cast() from sqlalchemy.dialects.postgresql import UUID from sqlalchemy import cast cast(MyModel.data['track']['id'], UUID) == UserTrack.id see the examples at https://docs.sqlalchemy.org/en/13/core/type_basics.html#sqlalchemy.types.JSON On Thu, Jun 20, 2019, at 3:25

Re: merging old versions

2019-06-20 Thread Mike Bayer
On Thu, Jun 20, 2019, at 1:45 PM, Michael Merickel wrote: > I think the basic idea is to create a database and codebase in the state of > the target revision. Then autogenerate a migration from nothing to that > revision - just like you would do when starting to use alembic from an > existing

Re: [sqlalchemy] Re: Masking SAWarning: Flushing object ... with incompatible polymorphic identity

2019-06-20 Thread Mike Bayer
On Thu, Jun 20, 2019, at 1:50 PM, Jonathan Vanasco wrote: > > > On Thursday, June 20, 2019 at 3:14:06 AM UTC-4, Chris Withers wrote: >> >> How can I indicate in my code that this is intentional and no warning >> should be omitted? > > > Personal option: > > I would not mask these. I

Re: [sqlalchemy] Masking SAWarning: Flushing object ... with incompatible polymorphic identity

2019-06-20 Thread Mike Bayer
On Thu, Jun 20, 2019, at 10:41 AM, Mike Bayer wrote: > > > On Thu, Jun 20, 2019, at 3:14 AM, Chris Withers wrote: >> Hi All, >> >> I'm getting this warning: >> >> SAWarning: Flushing object with incompatible >> polymorphic identity ; the obj

Re: [sqlalchemy] Masking SAWarning: Flushing object ... with incompatible polymorphic identity

2019-06-20 Thread Mike Bayer
On Thu, Jun 20, 2019, at 3:14 AM, Chris Withers wrote: > Hi All, > > I'm getting this warning: > > SAWarning: Flushing object with incompatible > polymorphic identity ; the object may not refresh > and/or load correctly (this warning may be suppressed after 10 occurrences) >

Re: [sqlalchemy] primaryjoin and remote/foreign sides

2019-06-20 Thread Mike Bayer
On Thu, Jun 20, 2019, at 8:39 AM, Julien Cigar wrote: > > > On Wednesday, June 19, 2019 at 9:53:42 PM UTC+2, Mike Bayer wrote: >> >> >> On Wed, Jun 19, 2019, at 10:50 AM, Julien Cigar wrote: >>> That's the (almost) final version if you're interrested:

Re: [sqlalchemy] primaryjoin and remote/foreign sides

2019-06-19 Thread Mike Bayer
ritten ? > > On Wednesday, June 19, 2019 at 4:44:55 PM UTC+2, Julien Cigar wrote: >> >> >> On Wednesday, June 19, 2019 at 4:09:55 PM UTC+2, Mike Bayer wrote: >>> >>> >>> On Wed, Jun 19, 2019, at 4:48 AM, Julien Cigar wrote: >>>> Tha

Re: [sqlalchemy] primaryjoin and remote/foreign sides

2019-06-19 Thread Mike Bayer
Class]).select_from(MyClass.__mapper__.selectable) > > Cheers, > Julien > > > On Wednesday, June 19, 2019 at 7:32:24 AM UTC+2, Mike Bayer wrote: >> >> This test doesn't run yet because it looks like you need to have >> initializers for things like Content.current_tran

Re: [sqlalchemy] primaryjoin and remote/foreign sides

2019-06-18 Thread Mike Bayer
in one query, and that it is transparent (it's a Pyramid plugin), that's why > I'm also using hybrid properties > > > On Tuesday, June 18, 2019 at 3:38:36 PM UTC+2, Mike Bayer wrote: >> >> >> On Tue, Jun 18, 2019, at 6:21 AM, Julien Cigar wrote: >>> Hello, &

Re: [sqlalchemy] Re: primaryjoin and remote/foreign sides

2019-06-18 Thread Mike Bayer
On Tue, Jun 18, 2019, at 9:00 AM, Julien Cigar wrote: > > > On Tuesday, June 18, 2019 at 12:20:55 PM UTC+2, Julien Cigar wrote: >> Hello, >> >> I'm trying to add a 'read-only' relationship involving a subquery and I have >> some problems with remote and foreign sides, SQLAlchemy returns: >>

Re: [sqlalchemy] How to Assign Blob Field?

2019-06-18 Thread Mike Bayer
On Tue, Jun 18, 2019, at 9:14 AM, Guy Zehavi wrote: > When I use sqlalchemy using mysql-connector-python to read unicode from a > blob I am getting: Hi there - While this issue may be impacted if you are using an old version of mysql-connector-python or of SQLAlchemy, assuming you are on

Re: [sqlalchemy] primaryjoin and remote/foreign sides

2019-06-18 Thread Mike Bayer
On Tue, Jun 18, 2019, at 6:21 AM, Julien Cigar wrote: > Hello, > > I'm trying to add a 'read-only' relationship involving a subquery and I have > some problems with remote and foreign sides, SQLAlchemy returns: > > sqlalchemy.exc.ArgumentError: Relationship Folder.current_translation could >

Re: [sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-17 Thread Mike Bayer
ure! Thanks! >> >> On Fri, Jun 14, 2019 at 5:50 PM Mike Bayer wrote: >>> __ >>> >>> >>> On Fri, Jun 14, 2019, at 12:46 PM, Mike Bayer wrote: >>>> >>>> >>>> On Fri, Jun 14, 2019, at 12:22 PM, João

Re: [sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-17 Thread Mike Bayer
here's no other alternative? > > > Thanks in advance, > João > > On Fri, Jun 14, 2019 at 5:52 PM João Miguel Neves > wrote: >> Cool, wasn't aware of that feature! Thanks! >> >> On Fri, Jun 14, 2019 at 5:50 PM Mike Bayer wrote: >>> __ >>> >>&

Re: [sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-14 Thread Mike Bayer
On Fri, Jun 14, 2019, at 12:46 PM, Mike Bayer wrote: > > > On Fri, Jun 14, 2019, at 12:22 PM, João Miguel Neves wrote: >> Not performance, actually to avoid a race condition with key/values written >> to JSONB fields. Ended up with the following function that we use

Re: [sqlalchemy] Apply a function to every query

2019-06-14 Thread Mike Bayer
On Fri, Jun 14, 2019, at 12:30 PM, Jonathan Vanasco wrote: > > > On Friday, June 14, 2019 at 9:33:49 AM UTC-4, Mike Bayer wrote: >> docs for this general idea are at >> https://docs.sqlalchemy.org/en/13/core/custom_types.html#redefining-and-creating-new-operators >>

Re: [sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-14 Thread Mike Bayer
you are updating columns in both "person" and "engineer". I might use SELECT..FOR UPDATE for a pessimistic approach. > > On Fri, Jun 14, 2019 at 5:07 PM Mike Bayer wrote: >> __ >> >> >> On Fri, Jun 14, 2019, at 11:49 AM, João Miguel Ne

Re: [sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-14 Thread Mike Bayer
to do an > update in a codepath that can have several different models passed to it) you're doing query.update() for performance reasons, right? yeah you probably have to do something like that, or just use regular session patterns to update data. > > TIA, > João > > On Fri, Jun 1

Re: [sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-14 Thread Mike Bayer
On Fri, Jun 14, 2019, at 10:30 AM, João Miguel Neves wrote: > Hi, > > I have a situation where an update tries to update the wrong table on when a > column comes from the parent table and is not on the current table. I'll > grant I didn't quite understand all the caveats in >

Re: [sqlalchemy] Apply a function to every query

2019-06-14 Thread Mike Bayer
On Fri, Jun 14, 2019, at 6:22 AM, Berislav Lopac wrote: > Hi, does anyone know of a simple way to apply a (SQL) function to each and > every query in an ORM model? For example, this article[0] suggests building a > lower()-based index for emails in order to normalise them, and then using >

Re: [sqlalchemy] Re: Bulk insert creating duplicate primary-keys

2019-06-12 Thread Mike Bayer
what's the default on the column? seems like that's the problem here. if this is an in-SQLAlchemy default, that won't work, you need to generate the uuids on the database side if you are using a SELECT. The functions are available through an extension on PG, there's background here:

Re: [sqlalchemy] inheritance hierarchy not updating second level hierarchy

2019-06-12 Thread Mike Bayer
On Wed, Jun 12, 2019, at 10:10 AM, Javier Martínez wrote: > Hi everyone, > I am searching but I find no solution for my issue that is why I decided to > ask here. Thanks in advance for your attention. > > The issue is related to the update of a second level hierarchy object Id. I > am

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-10 Thread Mike Bayer
On Mon, Jun 10, 2019, at 2:09 AM, Chris Withers wrote: > On 05/06/2019 20:47, Mike Bayer wrote: > > > > > >> The panacea I'm after is to be able to run the DDL in a transaction, run > >> each test in a subtransaction off that which is rolled back at the end &g

Re: [sqlalchemy] How to get output from PostgreSQL's VERBOSE functions

2019-06-09 Thread Mike Bayer
On Sun, Jun 9, 2019, at 1:33 AM, Zsolt Ero wrote: > I figured out the keyword is NOTICES. > > However this section of the docs doesn't work / didn't had any effect: > https://docs.sqlalchemy.org/en/13/dialects/postgresql.html#notice-logging that document assumes one is familiar with logging in

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-05 Thread Mike Bayer
On Wed, Jun 5, 2019, at 2:30 PM, Chris Withers wrote: > On 05/06/2019 17:15, Mike Bayer wrote: > > > >> How come close() doesn't rollback the SessionTransaction if it throws it > >> away? > > > > that's currently what .close() does, it discards th

Re: [sqlalchemy] Mixins and lazy (query) attributes

2019-06-05 Thread Mike Bayer
On Wed, Jun 5, 2019, at 12:02 PM, Christian Barra wrote: > Hi, I am trying to understand what the best approach is to have lazy > attributes defined on a mixin and then used them on the subclasses. > > Ideally I'd would like to defer the load of that attribute (controller) and > use `undefer`

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-05 Thread Mike Bayer
On Wed, Jun 5, 2019, at 11:47 AM, Chris Withers wrote: > On 05/06/2019 16:41, Mike Bayer wrote: > > > >> Which gives me: > >> > >> $ python sessions_are_weird.py > >> Traceback (most recent call last): > >> File "sessions_are_weird.py&q

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-05 Thread Mike Bayer
On Wed, Jun 5, 2019, at 3:50 AM, Chris Withers wrote: > On 04/06/2019 23:21, Mike Bayer wrote: > >> >> On Tue, Jun 4, 2019, at 4:33 PM, Chris Withers wrote: >>> >>> So, how do I roll back the further subtransaction created by the web >>> framew

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-05 Thread Mike Bayer
On Tue, Jun 4, 2019, at 6:31 PM, Chris Withers wrote: > On 04/06/2019 23:21, Mike Bayer wrote: > > > > > > I'm not following all your code but if there are two sessions in play > > I'd probably try to avoid that, there should be only one Session you > >

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-04 Thread Mike Bayer
On Tue, Jun 4, 2019, at 4:33 PM, Chris Withers wrote: > On 04/06/2019 14:49, Mike Bayer wrote: > > > > > > On Tue, Jun 4, 2019, at 2:15 AM, Chris Withers wrote: > >> Now, what I'm trying to test is that I haven't forgotten to include > >> the

Re: [sqlalchemy] when does session.transaction come into being?

2019-06-04 Thread Mike Bayer
On Tue, Jun 4, 2019, at 4:34 PM, Chris Withers wrote: > On 04/06/2019 14:47, Mike Bayer wrote: > > > > > > On Tue, Jun 4, 2019, at 3:05 AM, Chris Withers wrote: > >> Hi All, > >> > >> What creates session.transaction? I can't spot get __getatt

Re: [sqlalchemy] testing that a session is committed correctly

2019-06-04 Thread Mike Bayer
On Tue, Jun 4, 2019, at 2:15 AM, Chris Withers wrote: > Hi All, > > I'm working with the pattern described at > https://docs.sqlalchemy.org/en/13/orm/session_transaction.html#joining-a-session-into-an-external-transaction-such-as-for-test-suites > along with pytest and FastAPI, an async web

Re: [sqlalchemy] when does session.transaction come into being?

2019-06-04 Thread Mike Bayer
On Tue, Jun 4, 2019, at 3:05 AM, Chris Withers wrote: > Hi All, > > What creates session.transaction? I can't spot get __getattr__ magic, > but the only place in the code I see it being created is in .begin(...), > which has a docstring saying that it should no longer be used, so I feel >

Re: [sqlalchemy] Returning all columns except two

2019-06-03 Thread Mike Bayer
you would use deferred() on the mapping for this: https://docs.sqlalchemy.org/en/13/orm/loading_columns.html?highlight=deferred#deferred On Mon, Jun 3, 2019, at 8:29 PM, Desmond Lim wrote: > Hi All, > > I have a question which I think I know the answer to but I'd like to confirm. > > I have

Re: [sqlalchemy] advice/feedback sought on testing idea

2019-06-03 Thread Mike Bayer
On Mon, Jun 3, 2019, at 3:19 PM, Jonathan Vanasco wrote: > We have a fairly complex SqlAlchemy model that spans several integrated > applications (300+ tables). > > Our text columns are all of the `sqlalchemy.UnicodeText` class, however they > all have widely different 'cleaning' or

Re: [sqlalchemy] Re: Should load_only work with hybrid properties?

2019-06-03 Thread Mike Bayer
the .expression form of the hybrid_property to SELECT/calculate it in >> SQL >> >> with_entities(ORM_Class.column_attr,... etc) >> -Returns Tuple >> -Will *NOT* add necessary joins from relationship definitions in Model. Must >> join manually in query. >>

Re: [sqlalchemy] Re: Should load_only work with hybrid properties?

2019-06-03 Thread Mike Bayer
well hybrids don't apply to a load_only operation because they are not included in the query that emits when the ORM SELECTs for an object. that is, @hybrid_property.expression gives you a SQL expression, but that's never included when you say session.query(Task). It's only if you said,

Re: [sqlalchemy] Will calling a sessionmaker or closing a session block?

2019-06-02 Thread Mike Bayer
So that's an empty Session, which won't do anything immediately, however if anything is done on it that uses a database, then that all blocks, and if so, db.close() can also block because it has to cleanup the database connection which is definitely blocking IO stuff. If you didn't do anything

Re: [sqlalchemy] TypeDecorators don't know which database session to use

2019-05-30 Thread Mike Bayer
On Tue, May 28, 2019, at 9:10 AM, Chris Wilson wrote: > Dear Michael, > > I have discovered a limitation of TypeDecorators (custom column types): any > one that uses the database (e.g. to load objects serialised in a custom way) > has no way to know which database session to use. During

Re: [sqlalchemy] Re: TypeDecorators don't know which database session to use

2019-05-30 Thread Mike Bayer
On Thu, May 30, 2019, at 9:21 AM, Mike Bayer wrote: > > > On Thu, May 30, 2019, at 8:42 AM, Chris Wilson wrote: >> Hi Mike, >> >> On Wed, 29 May 2019 at 15:30, Mike Bayer wrote: >>> Note that we suggested approaches that work in conjunction with t

Re: [sqlalchemy] Re: TypeDecorators don't know which database session to use

2019-05-30 Thread Mike Bayer
On Thu, May 30, 2019, at 8:42 AM, Chris Wilson wrote: > Hi Mike, > > On Wed, 29 May 2019 at 15:30, Mike Bayer wrote: >> Note that we suggested approaches that work in conjunction with the >> serialized approach you gave, the @property approach and the mapper.load

Re: [sqlalchemy] Re: TypeDecorators don't know which database session to use

2019-05-29 Thread Mike Bayer
ould you accept my request to implement something like this? > > Thanks, Chris. > > On Tuesday, 28 May 2019 23:42:59 UTC+1, Jonathan Vanasco wrote: >> >> >> On Tuesday, May 28, 2019 at 4:35:32 PM UTC-4, Mike Bayer wrote: >>> >>> additionally, runnin

Re: [sqlalchemy] Re: TypeDecorators don't know which database session to use

2019-05-28 Thread Mike Bayer
On Tue, May 28, 2019, at 12:03 PM, Jonathan Vanasco wrote: > > > On Tuesday, May 28, 2019 at 9:10:19 AM UTC-4, Chris Wilson wrote: >> >> During initial load one can use a global session object, >> ** > > You should not do that. Global sessions are widely considered an anti-pattern.

Re: [sqlalchemy] Re: Slow execution of SQLAlchemy statements vs. plain text

2019-05-28 Thread Mike Bayer
On Tue, May 28, 2019, at 6:46 AM, Sebastian Meinhardt wrote: > The profiler results are in but they do not tell me anything that I did not > already find by manually stepping through the code. See my first post, above. > The method that takes all the time is `execute` of `cx_Oracle.Cursor`

Re: [sqlalchemy] Re: Slow execution of SQLAlchemy statements vs. plain text

2019-05-28 Thread Mike Bayer
On Tue, May 28, 2019, at 5:29 AM, Sebastian Meinhardt wrote: > Thank you for the pointers! After digging into this some more, I found that > this is definitely related to something in cartain versions of SQLAlchemy. I > also tried different versions of cx_Oracle (6.4.1, 7.1.2, and 7.1.3) but

Re: [sqlalchemy] Slow execution of SQLAlchemy statements vs. plain text

2019-05-27 Thread Mike Bayer
On Mon, May 27, 2019, at 12:05 PM, Sebastian Meinhardt wrote: > Hello, > > given an SQLAlchemy engine `con` (cx_oracle dialect) and a moderately complex > SQLAlchemy selectable object `sql`, the following code will consistently take > ~15 seconds: > > con.execute(sql).fetchall() > > Whereas

Re: [sqlalchemy] "Best" way to build a historical change tracking abstraction?

2019-05-25 Thread Mike Bayer
On Sat, May 25, 2019, at 5:10 AM, Antony Gelberg wrote: > I have a table "delivery" with a "status" column (yes, I still think in > tables, not sure if this is a cause for concern...). I need to refactor it to > track status history rather than just the current status. I would want to be >

Re: [sqlalchemy] Left join on one-to-many relationship with filters

2019-05-24 Thread Mike Bayer
On Fri, May 24, 2019, at 12:48 PM, Jonathan Vanasco wrote: > I agree with Simon, and I think I'm very much -1 on the usage of > contains_eager above (and I think that ticket you linked to, Mike). I find > that sort of stuff causes a lot of bugs in the long run. > > I am looking at it from

Re: [sqlalchemy] Left join on one-to-many relationship with filters

2019-05-24 Thread Mike Bayer
d > see this filter and apply it. > My usage then becomes : > qry_users = session.query(User).options(filterrelated(User.addresses, > Address.city=='Mumbai')).all() > > > > On Thu, May 23, 2019 at 11:46 PM Mike Bayer wrote: >> __ >> >> >> On Thu, May 23, 2

Re: [sqlalchemy] Left join on one-to-many relationship with filters

2019-05-23 Thread Mike Bayer
in to it again, to filter it. >> The transform looks useful. >> >> Another thing : Is it possible to specify which relation columns to fetch >> when i declare the relation ? >> >> regards, >> manoj >> >> On Wed, May 22, 2019 at 12:05 PM Mike Bayer

Re: [sqlalchemy] Fast joins on multiple tables based on relationships

2019-05-22 Thread Mike Bayer
ormance.html#how-can-i-profile-a-sqlalchemy-powered-application as well as demonstrations at https://docs.sqlalchemy.org/en/13/orm/examples.html#examples-performance . > > > > On Wednesday, May 22, 2019 at 4:49:58 PM UTC-7, Mike Bayer wrote: >> >> >> On Wed,

Re: [sqlalchemy] Fast joins on multiple tables based on relationships

2019-05-22 Thread Mike Bayer
d IN (?, ?, ?) ORDER BY c.b_id 2019-05-22 19:39:25,164 INFO sqlalchemy.engine.base.Engine (1, 2, 3) > > > > > So I was wondering if anyone knows of a way to do that query so it is fast. > Perhaps the 3x number of queries is because it eager loads Address.residents

Re: [sqlalchemy] Fast joins on multiple tables based on relationships

2019-05-22 Thread Mike Bayer
On Wed, May 22, 2019, at 3:56 PM, bvbav wrote: > Hi > > I was wondering if I can get some advice on this... > > Let's say I have these models: > > class Pet(db.Model): > id = db.Column(..., primary_key=True) > name = db.Column(...) > > > resident_pet = db.Table('resident_pet',

Re: [sqlalchemy] Conditional onupdate

2019-05-22 Thread Mike Bayer
of statement to be generated using the before_execute or ORM level before_update / etc. events I illustrated earlier. > > On Thursday, May 16, 2019 at 2:49:56 PM UTC-7, Mike Bayer wrote: >> On Thu, May 16, 2019 at 4:26 PM Tony Cao wrote: >> > >> > Ohh I see thanks for the he

Re: [sqlalchemy] Left join on one-to-many relationship with filters

2019-05-22 Thread Mike Bayer
On Wed, May 22, 2019 at 1:02 AM Manoj Mokashi wrote: > > Hi Michael, > > It would be nice to have something like options(filterrelated(relation, > filter)) > That way, since the join is already specified in the relation, we don't have > to add it again. > Or is that difficult due to lazyloading

Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-20 Thread Mike Bayer
I hope you can forgive that I've been allowing you to figure this out on your own as the emails here seem to be more of glimpses of an in-progress situation rather than something those of us who are outside of your project can easily engage within, if you are stuck on something is there any chance

Re: [sqlalchemy] Receiving this error: sqlalchemy.exc.DBAPIError: (pyodbc.Error) ('HYC00', u'[HYC00] [Microsoft][ODBC SQL Server Driver]Optional feature not implemented (0) (SQLBindParameter)')

2019-05-17 Thread Mike Bayer
On Fri, May 17, 2019 at 4:39 PM Alex Net wrote: > > Hello! I have been writing code that would allow me to read from an Excel > sheet and writing it in a MS SQL Database. The code was functioning well, > meaning it was running and writing all cells until it got to cell E,23 , > where it

Re: [sqlalchemy] Case Sensitivity at query time for SQL Server

2019-05-17 Thread Mike Bayer
On Fri, May 17, 2019 at 9:43 AM Massi wrote: > > Hi, > > I'm trying to issue a query in SQL Server via select(cols, cond, ...) and I > would like to add collation at query execution time for executing the query > in a case sensitive mode. > I tried this: > > cond = and_(tab.c.col3=="mystring1",

Re: [sqlalchemy] InvalidRequestError: Query.limit() being called on a Query with an existing full statement - can't apply criterion.

2019-05-17 Thread Mike Bayer
imit(page_size) > File "", line 2, in limit > > File > "/opt/rh/rh-python36/root/usr/lib64/python3.6/site-packages/sqlalchemy/orm/base.py", > line 219, in generate > assertion(self, fn.__name__) > File > "/opt/rh/rh-python36/root/usr/li

Re: [sqlalchemy] Conditional onupdate

2019-05-16 Thread Mike Bayer
me what you get if you want to work with that. > > On Wednesday, May 15, 2019 at 5:30:06 PM UTC-7, Mike Bayer wrote: >> >> On Wed, May 15, 2019 at 6:10 PM Tony Cao wrote: >> > >> > I mean query.update(). >> > >> > Ah our goal was to make it s

Re: [sqlalchemy] InvalidRequestError: Query.limit() being called on a Query with an existing full statement - can't apply criterion.

2019-05-16 Thread Mike Bayer
the stack trace would show you where it's going wrong. Are you calling first() on the query? that applies limit(). Stack trace will show this.Can't apply limit() to a textual query because the text is already written. On Thu, May 16, 2019 at 10:16 AM Xander Cage wrote: > > hi all. > >

Re: [sqlalchemy] Conditional onupdate

2019-05-15 Thread Mike Bayer
enerated by query.update(). See https://docs.sqlalchemy.org/en/13/orm/events.html?highlight=before_compile_update#sqlalchemy.orm.events.QueryEvents.before_compile_update. Additional detail regarding .values will be up within 30 minutes. > > > On Wednesday, May 15, 2019 at 2:38:19 PM UT

Re: [sqlalchemy] Conditional onupdate

2019-05-15 Thread Mike Bayer
looks like the before_update event isn't triggered when doing > bulk query updates, which we'd like to also update on. Is there a way to > track those? > > On Wednesday, May 15, 2019 at 10:38:24 AM UTC-7, Mike Bayer wrote: >> >> you can inspect() the object and look at &g

Re: [sqlalchemy] Conditional onupdate

2019-05-15 Thread Mike Bayer
s looking at the history of the attribute state - is there a > better way? > > On Wednesday, May 15, 2019 at 7:55:44 AM UTC-7, Mike Bayer wrote: >> >> On Mon, May 13, 2019 at 4:18 PM Tony Cao wrote: >> > >> > Hi all, >> > >> > Is there way to u

Re: [sqlalchemy] Conditional onupdate

2019-05-15 Thread Mike Bayer
On Mon, May 13, 2019 at 4:18 PM Tony Cao wrote: > > Hi all, > > Is there way to use Column.onupdate conditionally? For example, say I have: > > class A(Base): > foo = Column(String) > bar = Column(String) > foo_updated = Column(DateTime, onupdate=update_fn) # Should only update >

Re: [sqlalchemy] Re: Differences between `op.get_bind()` and `op.get_bind().engine.connection()`

2019-05-15 Thread Mike Bayer
On Wed, May 15, 2019 at 5:23 AM Diego Quintana wrote: > > Hello again! > > This worked, thanks! > > I noticed that if I use `bind.connection`, I do not need to call > `engine.raw_connection` anymore. I wonder why is this. Is this a proxy to a > raw connection or it was never necessary from the

Re: [sqlalchemy] Re: Structured Inheritance model for ORM

2019-05-15 Thread Mike Bayer
On Wed, May 15, 2019 at 4:12 AM Marcel Zoll wrote: >> >> Thank you, Mike, for having a look at my clumsy code (there were some >> mistakes in the code, I only saw later) and making this effort. > > > Firstly, I have done a bit more tinkering yesterday, and also got aware, that > the Mapper or

Re: [sqlalchemy] Structured Inheritance model for ORM

2019-05-14 Thread Mike Bayer
Hi there - I normally wouldn't do things this way, however in seeking to provide an alternative architecture, the specific example you've given does work when used with the correct constructs, so I can provide both architectures. So you would need to illustrate specific scenarios that aren't

Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-13 Thread Mike Bayer
atustype_id > 50) > > Le lun. 13 mai 2019 à 16:26, Mike Bayer a > écrit : > >> Hi - >> >> I was hoping someone could jump in on this. >> >> do you know the SQL that you want to emit? E.g. plain SQL string. I >> can help you do that part. >

Re: [sqlalchemy] Re: Query last relation created and attributes

2019-05-13 Thread Mike Bayer
Hi - I was hoping someone could jump in on this. do you know the SQL that you want to emit? E.g. plain SQL string. I can help you do that part. On Mon, May 13, 2019 at 9:11 AM Scheck David wrote: > > I think I'm near but I can't finish : > > for all the structure : https://dpaste.de/fek5#L

Re: [sqlalchemy] Re: Differences between `op.get_bind()` and `op.get_bind().engine.connection()`

2019-05-10 Thread Mike Bayer
On Fri, May 10, 2019 at 10:34 AM Diego Quintana wrote: > > Thanks for your answer. If I got this right, it makes sense to think of two > different transactions happening, being the second one not able to "see" what > the first has done (e.g. creating tables) until it has finished (i.e. when >

Re: [sqlalchemy] Differences between `op.get_bind()` and `op.get_bind().engine.connection()`

2019-05-10 Thread Mike Bayer
On Fri, May 10, 2019 at 7:09 AM Diego Quintana wrote: > > Hello! I'm trying to seed my database using my first migration script, and I > have trouble understanding what `op.get_bind()` returns, and mainly the > difference between `Connection` and `engine.connection()`. Say I have a > migration

Re: [sqlalchemy] virtual relationship..?

2019-05-09 Thread Mike Bayer
is the general idea, one attribute that is merging two totally different relationships? You'd just build a @property that creates a view of the two relationships when accessed. Kind of like an association proxy, but less flexible and read-only. On Thu, May 9, 2019 at 6:38 AM Julien Cigar

Re: [sqlalchemy] MySQL optimizer hints not working with Query API

2019-05-08 Thread Mike Bayer
query_str_with_hint = query_str[:sel_ind + 6] + hint_str + >> query_str[sel_ind+6:] >> query_stmt_with_hint = text(query_str_with_hint, >> bindparams=query_binds) >> query = >> db.session.query(ProvenancePrototype).from_statement(query_stmt_with_hint) >> >

Re: [sqlalchemy] MySQL optimizer hints not working with Query API

2019-05-08 Thread Mike Bayer
Update, please use prefix_with(), sorry I forgot this goes into the right place: query.prefix_with("/*+ MAX_EXECUTION_TIME(3) */") will add a note to the docs On Wed, May 8, 2019 at 10:11 AM Mike Bayer wrote: > > Additionally, those hints seem to be a new

Re: [sqlalchemy] MySQL optimizer hints not working with Query API

2019-05-08 Thread Mike Bayer
Additionally, those hints seem to be a new feature (http://mysqlserverteam.com/whats-new-in-mysql-5-7-first-release-candidate/) for a hint format that was previously not present in MySQL and don't seem to be present in MariaDB either, and surprisingly enough they look just like Oracle optimizer

Re: [sqlalchemy] MySQL optimizer hints not working with Query API

2019-05-08 Thread Mike Bayer
Hi there- I see you are using str() to get the string representation, which will not give you a MySQL representation. DId you read https://docs.sqlalchemy.org/en/13/faq/sqlexpressions.html#how-do-i-render-sql-expressions-as-strings-possibly-with-bound-parameters-inlined ? On Wed, May 8, 2019

Re: [sqlalchemy] Oracle Bulk inserts returning array of IDs possible?

2019-05-06 Thread Mike Bayer
On Mon, May 6, 2019 at 5:12 PM Chris Stephens wrote: > > Is is possible to implement the following behavior in SQLAlchemy against an > Oracle database? (Bulk inserts returning PK IDs generated by trigger/sequence > on PK column in database) The code you have already does what you need and is

Re: How to handle `default` column values before/after commit()

2019-05-06 Thread Mike Bayer
On Mon, May 6, 2019 at 12:06 AM wrote: > > Suppose the following code: > > # We define a base for all DB objects, currently empty. > class _Base: > pass > > Base = declarative_base(cls=_Base, metadata=MetaData(naming_convention=…)) > > # Then the objects. > class User(Base): >

Re: [sqlalchemy] why MySQL DOUBLE is asdecimal=True by default

2019-04-29 Thread Mike Bayer
still looks like DOUBLE should be dealing with Python floats. DOUBLE_PRECISION in the Oracle dialect is also Float and doesn't default to decimal coercion. We can fix this problem, it's just one of those changes that you have to warn users like crazy on and then just do the change on a major

Re: [sqlalchemy] Possible regression?

2019-04-29 Thread Mike Bayer
es which I largely copied without deeply considering it beyond the heavy thinking they did up front; the pycon talk I did after several years of learning how the Session was actually supposed to work which itself required that I redesigned half the thing in version 0.5. > > -Lyla > &g

Re: [sqlalchemy] why MySQL DOUBLE is asdecimal=True by default

2019-04-29 Thread Mike Bayer
On Mon, Apr 29, 2019 at 1:13 PM mdob wrote: > > Just out of curiosity, why it was decided that MySQL DOUBLE, which is > approximation, will be presented in ORM as Decimal by default instead of > float? > > MySQL DOUBLE - > https://dev.mysql.com/doc/refman/5.5/en/floating-point-types.html >

Re: [sqlalchemy] Possible regression?

2019-04-29 Thread Mike Bayer
gt; object just knows which TasselThreads are its own. That doesn't fit the > common university model of the way foreign key only one-to-many relationships > work, but I didn't think about it too hard. I was just thinking that "yes, of > course you need to persist the head before pe

Re: [sqlalchemy] Possible regression?

2019-04-29 Thread Mike Bayer
On Mon, Apr 29, 2019 at 7:22 AM Lyla Fischer wrote: > > If I can comment on what seems instinctive to someone who just recently read > the documentation, and made assumptions based off of it: My understanding was > that the relationship abstractions were supposed to be about making foreign >

Re: [sqlalchemy] Possible regression?

2019-04-28 Thread Mike Bayer
depending on the cascading to get > everything into the database and linked up appropriately, andt I might need > to spend some time studying exactly how cascading works in order to be able > to reliably use the relationship feature in the future. > > -Lyla > > On Su

Re: [sqlalchemy] Possible regression?

2019-04-28 Thread Mike Bayer
://github.com/sqlalchemy/sqlalchemy/issues/4647 On Sun, Apr 28, 2019 at 12:26 PM Mike Bayer wrote: > > Hi there, > > I appreciate everyone chiming in to look at this! > > However, it's something simple and has to do with one of the API > quirks that we have to decide if we w

Re: [sqlalchemy] Possible regression?

2019-04-28 Thread Mike Bayer
Hi there, I appreciate everyone chiming in to look at this! However, it's something simple and has to do with one of the API quirks that we have to decide if we want to keep long term. Background is at https://docs.sqlalchemy.org/en/13/orm/cascades.html#backref-cascade. Basically, when you do

Re: [sqlalchemy] association proxy through composite key relation not working as expected. "KeyError: 'request_server'"

2019-04-25 Thread Mike Bayer
d raise for this condition, e.g. pointing it to itself. On Thu, Apr 25, 2019 at 11:00 AM Mike Bayer wrote: > > On Thu, Apr 25, 2019 at 8:34 AM Jan Sakalos wrote: > > > > Hello, > > > > I have to association proxies in code one is working and other not. I went >

Re: [sqlalchemy] association proxy through composite key relation not working as expected. "KeyError: 'request_server'"

2019-04-25 Thread Mike Bayer
On Thu, Apr 25, 2019 at 8:34 AM Jan Sakalos wrote: > > Hello, > > I have to association proxies in code one is working and other not. I went > through it many times and wasnt able to identify issue. > Also please can you give me advice how to debug such issues if there is any? The error is that

Re: [sqlalchemy] Checking approaches around parallel data import for records

2019-04-24 Thread Mike Bayer
On Wed, Apr 24, 2019 at 12:19 PM Markus Elfring wrote: > > > Why not report these problems to the cochinelle tool > > which you are trying to integrate ? > > I suggest to take another look at corresponding information sources. > https://systeme.lip6.fr/pipermail/cocci/2019-April/thread.html >

<    5   6   7   8   9   10   11   12   13   14   >