Re: [sqlalchemy] return value of array at a specific index

2016-05-22 Thread Mike Bayer
On 05/22/2016 07:12 PM, Brian Cherinka wrote: What's the proper way to return in an ORM query the value of a Postgres array attribute at a given specific index within the array? I have a db table with a column called value, which is a 2d array, defined as REAL[][]. My ModelClass is defined

Re: [sqlalchemy] Dialect not replacing ? with parameter

2016-05-22 Thread Mike Bayer
with the anon_1. I can't tell if that is SQL Alchemy thing or a caravel thing. I am still digging, and will continue to, but if you or anyone here could help me debug and/or point me in the right direction, I figured it would be good to articulate my thoughts. On Thu, May

Re: [sqlalchemy] How to map class to multiple tables (for sharding purpose)

2016-05-22 Thread Mike Bayer
19 May 2016 18:30:51 UTC+3, Mike Bayer wrote: Well if you want to see some examples of on-the-fly mappers for different databases that nonetheless map to the same class take a look at https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/EntityName <https://bitbucket.org

Re: [sqlalchemy] Calculated relationships

2016-05-23 Thread Mike Bayer
reported issue here doesn't immediately turn up anything. Feel free to poke around. I'll try to remember to press the "post" button individually first next time and see if it takes. On 05/23/2016 12:55 AM, Jonathan Vanasco wrote: On Sunday, May 22, 2016 at 11:45:23 PM UTC

Re: [sqlalchemy] How to get unambiguous column name for selectable?

2016-05-24 Thread Mike Bayer
q = session.query(Foo).options(sa.orm.joinedload('bars')) q = q.order_by(q.with_labels().statement.c.foo_name) On 05/24/2016 05:26 AM, Andrew Pashkin wrote: Here is the working example: import sqlalchemy as sa from sqlalchemy.ext.declarative import declarative_base engine =

Re: [sqlalchemy] Update Primary Key in the Session Data based Unique Key

2016-05-24 Thread Mike Bayer
I'm assuming this is data from a flat file or XML or something. 1. Read the rows in chunks. say 1000 at a time. 2. organize the system by which you will regenerate the primary key from a given row. For each chunk, run this method on each row and associate the primary key with each row in

Re: [sqlalchemy] Calculated relationships

2016-05-21 Thread Mike Bayer
You can put whatever expressions you want in relationships provided they provide enough information to map them the way relationship expects, the examples at http://docs2.sqlalchemy.org/en/latest/orm/join_conditions.html#creating-custom-foreign-conditions should get you started. On Friday, May

Re: [sqlalchemy] accessing base class on hybrid expressions from the class side

2016-05-10 Thread Mike Bayer
in 1.1 these hybrids will have the class_ attribute like other attributes. Until then you can probably add your own class_ attribute to the object which you are returning. Also, using a custom Comparator class (see the example in the hybrid docs) will also return an instrumented attribute

Re: [sqlalchemy] validate collections

2016-05-11 Thread Mike Bayer
here no exception is expected see attached. you'd need to show me how to illustrate the .tags collection storing two TagAssociation objects when you've explicitly set the collection to store a single TagAssociation I don’t get it, where do I set that? Am 05.05.2016 um 23:26 schrie

Re: [sqlalchemy] accessing base class on hybrid expressions from the class side

2016-05-10 Thread Mike Bayer
(datadb.Cube.plateifu, "class_", datadb.Cube.id.class_) but it didn't seem to work. But I'll dig a bit deeper. If I can't get something working with a 1.0X release, I'll try the 1.1 in bitbucket. On Tuesday, May 10, 2016 at 2:32:22 PM UTC-4, Mike Bayer wrote: in 1.1 these hybrids will have

Re: [sqlalchemy] accessing firebird on windows from linux

2016-05-17 Thread Mike Bayer
firebird is very obscure / esoteric. I'd get a straight fdb DBAPI working first then we can work backwards to get the right URL. On 05/17/2016 10:42 AM, robert rottermann wrote: Hi there, I try to access a firebird db on windows from my ubuntu box. I have a gui-tool (FlameRobin), from

Re: [sqlalchemy] Re: SQLAlchemy 1.0.13 released

2016-05-17 Thread Mike Bayer
2016 at 5:31:25 PM UTC-4, Mike Bayer wrote: Apparently, readthedocs has been not building for over a week, so at the moment the CHANGES link below is very stale. We are trying to get RTD to respond for help. Last month they had a big change and migrated projects from subdomai

Re: [sqlalchemy] subqueryload - off-by-one issue?

2016-05-12 Thread Mike Bayer
make sure you are always using order_by if you're doing any kind if limit/offset (including if you call the first() accessor), see the notes at http://docs.sqlalchemy.org/en/rel_1_0/orm/loading_relationships.html#the-importance-of-ordering and

[sqlalchemy] Re: SQLAlchemy 1.0.13 released

2016-05-16 Thread mike bayer
impact among other things using the Query.get() method on a primary key that’s a bytes object.¶ References: #3660 On 05/16/2016 04:52 PM, Mike Bayer wrote: SQLAlchemy release 1.0.13 is now available. Release 1.0.13 fixes a variety of issues targeted at the 1.0 series that have been

[sqlalchemy] SQLAlchemy 1.0.13 released

2016-05-16 Thread Mike Bayer
SQLAlchemy release 1.0.13 is now available. Release 1.0.13 fixes a variety of issues targeted at the 1.0 series that have been resolved over the past several weeks. Fixes include small issues repaired in the ORM, Core, Postgresql, Oracle, SQL Server dialects. Most issues are very minor with

Re: [sqlalchemy] mysql/sqlite date workaround

2016-05-16 Thread Mike Bayer
On 05/16/2016 04:34 PM, Михаил Доронин wrote: I've opened issue here <https://bitbucket.org/zzzeek/sqlalchemy/issues/3714/sqlalchemy-core-returns-string-instead-of>, please read it, it's very brief. Now Mike Bayer says that it's not a sqlalchemy bug, and says that I can use cast t

Re: [sqlalchemy] Documented URL string for Google Cloud SQL confusing

2016-05-11 Thread Mike Bayer
Google cloud SQL was provided by contributors and I know nothing about how it works. Please provide a pull request repairing these issues, or otherwise I'll just remove the documentation if it is misleading. To build the documentation, do "make html" in the doc/build directory after

Re: [sqlalchemy] exc.NoForeignKeysError

2016-05-15 Thread Mike Bayer
I think your fk needs to read "clients.clientid". It uses the table name. On Sunday, May 15, 2016, Aaron Dalton wrote: > I am pulling my hair out here! I just wasted an hour trying to get this to > work. I already have one set of models working fine. I simply created

Re: [sqlalchemy] bulk_update_mapping stale data error

2016-05-03 Thread Mike Bayer
On 05/03/2016 01:15 PM, Andrew Martin wrote: This is an admittedly wonky situation. And I don't have much code to offer because I think the problem is conceptual on my part, rather than code-related. We're basically using google spreadsheets as a quick and dirty interface for certain types of

Re: [sqlalchemy] validate collections

2016-05-05 Thread Mike Bayer
On 05/03/2016 06:28 PM, Tim-Christian Mundt wrote: I have entities which I’d like to tag with tags from a vocabulary. The associations between entities and tags are implemented with „manual M:N“, because they carry more information. class Entity(Base): id = Column(Integer,

Re: [sqlalchemy] MySQL defining full text indexes and using MATCH AGAINST, SQLAlchemy way

2016-05-06 Thread Mike Bayer
On 05/06/2016 02:31 AM, Dev Mukherjee wrote: On Thu, May 5, 2016 at 11:54 PM, Mike Bayer <mike...@zzzcomputing.com <mailto:mike...@zzzcomputing.com>> wrote: most expedient way would be to use CREATE INDEX and specify it within DDL(): ddl = DDL("CREATE FULLTE

Re: [sqlalchemy] MySQL defining full text indexes and using MATCH AGAINST, SQLAlchemy way

2016-05-05 Thread Mike Bayer
most expedient way would be to use CREATE INDEX and specify it within DDL(): ddl = DDL("CREATE FULLTEXT INDEX some_idx ON table(colname)") you can then just invoke it: conn.execute(ddl) or add it as a table event event.listen(table, "after_create", ddl) we can of course add an option to

Re: [sqlalchemy] MSSQL OperationalError when offsetting and ordering by an aggregated column

2016-05-10 Thread Mike Bayer
On 05/10/2016 11:22 AM, Craig Weber wrote: Hello, I believe I've encountered a bug, but I wanted to verify it here before polluting the issue tracker. When I compile the following SQLAlchemy query for postgres, everything seems to work as expected; however, it fails for MSSQL. | |price_sum

Re: [sqlalchemy] Re: MSSQL OperationalError when offsetting and ordering by an aggregated column

2016-05-10 Thread Mike Bayer
On 05/10/2016 01:10 PM, Craig Weber wrote: Great; do you know when this will be released? I'm unfamiliar with SQLAlchemy's release cadence. the minor fix releases generally come as a particular point version has either had about 6-8 weeks in development, or if it accumulates any

Re: [sqlalchemy] Changing columns in query

2016-05-02 Thread Mike Bayer
пользователь Mike Bayer написал: yes please use query.with_entities http://docs.sqlalchemy.org/en/rel_1_0/orm/query.html?highlight=query.with_entities#sqlalchemy.orm.query.Query.with_entities <http://docs.sqlalchemy.org/en/rel_1_0/orm/query.html?highlight=query.with_entit

Re: [sqlalchemy] Order of properties from inspection

2016-05-09 Thread Mike Bayer
not a bad question. Those attributes are the mapper-assigned attributes and I'd guess that because address_ has an alternate name, declarative is setting it up in a different step. The attributes on a class can't be ordered in any case. To get the real order of columns at the Core level

Re: [sqlalchemy] Order of properties from inspection

2016-05-09 Thread Mike Bayer
approach: Venue.__table__.columns.keys() ['id', 'name', 'address'] But how I can get class attributes in the same order as real table columns? On Mon, May 9, 2016 at 8:31 PM, Mike Bayer <mike...@zzzcomputing.com <mailto:mike...@zzzcomputing.com>> wrote: not a bad question. Thos

Re: [sqlalchemy] How to generate a file with DDL in the engine's SQL dialect? How to copy engine?

2016-05-09 Thread Mike Bayer
On 05/09/2016 10:51 AM, Piotr Dobrogost wrote: At http://stackoverflow.com/q/870925/95735 there's a question titled "How to generate a file with DDL in the engine's SQL dialect in SQLAlchemy?"with the answer which gives the following code: engine = create_engine( 'mssql+pyodbc://./MyDb',

Re: [sqlalchemy] Order of properties from inspection

2016-05-09 Thread Mike Bayer
umns, key=lambda col: col._creation_order)] ['id', 'name', 'address'] I want to get ['id', 'name', 'address_']. On Mon, May 9, 2016 at 9:01 PM, Mike Bayer <mike...@zzzcomputing.com <mailto:mike...@zzzcomputing.com>> wrote: ideally declarative would try to preserve this ordering for

Re: [sqlalchemy] Composite Column questions and practices

2016-04-14 Thread Mike Bayer
On 04/11/2016 08:08 PM, Matthew Blain wrote: Hi, I'm learning SQLAlchemy, and a Composite Column seems like a very useful concept. However, there are very few mentions of it I can find. So some related questions after reading some docs and some experimentation. * 'Hiding'--let's say that

[sqlalchemy] Alembic 0.8.6 released

2016-04-14 Thread Mike Bayer
Alembic 0.8.6 is now available. Release 0.8.6 fixes a small handful of bugs including in the area of batch migrations and Postgresql server default comparison. It also enhances the behavior of the "alembic revision" command, such that if the revision fails due to a compile-time or runtime

Re: [sqlalchemy] NoSuchColumnError happens when multiple processes concurrently access to a row with locking

2016-04-19 Thread Mike Bayer
On 04/18/2016 08:54 PM, Shingo Toda wrote: Hi all I am now seeing the SQLAlchemy raise 'NoSuchColumnError' occasionally when concurrent accesses happen with 'select for update'. My application uses * SQLAlchemy 0.8.4 * MySQL-python 1.2.3 * CentOS6.7 * python 2.6 *

Re: [sqlalchemy] [graphene] No inspection system is available for object of type

2016-04-19 Thread Mike Bayer
this issue involves the use of graphene-specific APIs which are not part of the SQLAlchemy project. You will have better luck asking the maintainers of graphene directly. On 04/19/2016 02:16 AM, 刘邦瑞 wrote: Hi, I encountered this problem when I try to use Automap methods in Graphene.

Re: [sqlalchemy] Posting SQLAlchemy-Continnum related posts to this group?

2016-04-18 Thread Mike Bayer
I try to discourage posts about other projects here only because it is often the case that the maintainers of those projects aren't being responsive to user issues, so posting here seeks to take advantage of the extremely high level of responsiveness we have here. However we really can't

Re: [sqlalchemy] NoSuchColumnError happens when multiple processes concurrently access to a row with locking

2016-04-19 Thread Mike Bayer
. On Tuesday, April 19, 2016 at 10:56:06 PM UTC+9, Mike Bayer wrote: On 04/18/2016 08:54 PM, Shingo Toda wrote: > Hi all > > I am now seeing the SQLAlchemy raise 'NoSuchColumnError' occasionally > when concurrent accesses happen with 'select for update'.

Re: [sqlalchemy] Re: __table_alias__ option

2016-04-20 Thread Mike Bayer
if intellisense is scanning source code to determine what elements an object has, then I don't see any way for it to do this unless you actually typed in a new definition of some kind that laid out all the attributes you'd like intellisense to know about. IMO such tools are not practical

Re: [sqlalchemy] Accessing name of the table in class' attributes.

2016-04-20 Thread Mike Bayer
On 04/20/2016 07:35 AM, Piotr Dobrogost wrote: Having this code class Base(object): @declared_attr def __tablename__(cls): return '{0}s'.format(camel_case_to_name(cls.__name__)) class Model(Base): id = Column(Integer, Sequence(???, optional=True), primary_key=True) is

Re: [sqlalchemy] __table_alias__ option

2016-04-20 Thread Mike Bayer
from sqlalchemy.orm import aliased as _aliased def aliased(entity): return _aliased(entity, name=entity.__table_alias__) ? On 04/20/2016 10:25 AM, SPetro wrote: Hi, is possible to have "default" alias for table class Cwle(Base): __tablename__ = 'CardiacWaitListEntry'

Re: [sqlalchemy] tiny new tool for making sample objects for tests

2016-04-14 Thread Mike Bayer
On 04/14/2016 07:33 PM, Chris Withers wrote: Hi All, I've just released this tiny library for making sample objects for testing. Here's a SQLAlchemy example: class Parent(Base): __tablename__ = 'parent' id = Column(Integer,

Re: [sqlalchemy] where is InstanceState.key set?

2016-04-21 Thread Mike Bayer
be is public: http://docs.sqlalchemy.org/en/rel_1_0/orm/mapping_api.html#sqlalchemy.orm.util.identity_key On 21/04/2016 00:23, Mike Bayer wrote: on the load side in loading.py and on the persistence side in session.py _register_newly_persistent. On 04/20/2016 01:28 PM, Chris Withers wrote

Re: [sqlalchemy] Guaranteeing same connection for scoped session

2016-04-13 Thread Mike Bayer
Well scopedsession.remove throws away the session, so yeah either don't call that , or set up the connection immediately on the next session. On Wednesday, April 13, 2016, Kent Bower wrote: > About a year ago you helped me ensure my scoped session gets the same > connection

Re: [sqlalchemy] where is InstanceState.key set?

2016-04-20 Thread Mike Bayer
on the load side in loading.py and on the persistence side in session.py _register_newly_persistent. On 04/20/2016 01:28 PM, Chris Withers wrote: Hey All, Where is InstanceState.key set? I'm looking for the code that builds the key used in the identity_map of the session. Turns out to be

Re: [sqlalchemy] SQLAlchemy 1.0.12 use inner JOIN instead of LEFT OUTER JOIN

2016-04-26 Thread Mike Bayer
On 04/26/2016 12:22 PM, Alex Dev wrote: These two work. However I think that I cannot do that in my real query because it is a bit more complex. For the sake of simplifying my question, I reduced the query to the minimum but I realize it is now hard so see why I was using contains_eager or

Re: [sqlalchemy] MySQL defining full text indexes and using MATCH AGAINST, SQLAlchemy way

2016-05-07 Thread Mike Bayer
On Saturday, May 7, 2016, Dev Mukherjee wrote: > >> >> > If I create the full text and include multiple fields in the index > > CREATE FULLTEXT INDEX `keyword_search` ON > customer(name,physical_address_street,physical_address_suburb, >

Re: [sqlalchemy] Is there a way to create custom classes that inherit from sqlalchemy models in external library?

2016-07-22 Thread Mike Bayer
54, in __get__ obj.__dict__[self.__name__] = result = self.fget(obj) File "/mnt/hgfs/Documents/git/cc-mysql/env/lib/python3.5/site-packages/sqlalchemy/orm/instrumentation.py", line 116, in mapper raise exc.UnmappedClassError(self.class_) sqlalchemy.orm.exc.UnmappedClassError: Class

Re: [sqlalchemy] One Class Mapping Multiple Tables

2016-07-22 Thread Mike Bayer
On 07/21/2016 07:06 PM, John Robson wrote: Hi everyone, I want to store the minute price of all 500 stocks from S 500. This means more than 500 million of rows + almost 200K updates per day + (sometimes) past values must be updated (to adjust ex-dividend, splits). Instead of creating a BIG

Re: [sqlalchemy] Restrict update and delete based on attribute

2016-07-26 Thread Mike Bayer
On 07/26/2016 02:29 PM, drMental wrote: I'd like to restrict deletion and updates on an object based on the boolean attribute 'locked' on the same object. I've managed to successfully suppress updates but it doesn't seem to work for deletes with the following code. @listen_for(mapper,

Re: [sqlalchemy] Implicit join condition

2016-07-13 Thread Mike Bayer
On 07/13/2016 02:29 AM, Seth P wrote: [Apologies for posting an incomplete version of this post earlier. Please ignore it.] If B has a ForeignKey (and relationship) to A (e.g. B.a_id -> A.id), then I can write query(B.b_num).join(A) without specifying the condition, and SQLAlchemy will figure

Re: [sqlalchemy] How to get unambiguous column name for selectable?

2016-07-21 Thread Mike Bayer
On 07/21/2016 10:32 AM, Andrew Pashkin wrote: On 07/21/2016 05:13 PM, Mike Bayer wrote: Are entities in column_descriptions ordered? yes In what order? Is there something similar for SA SQL expressions? select.c How to retrieve an entity from select.c, which is suitable for putting

Re: [sqlalchemy] Re: explicitly add objects to identity map

2016-07-21 Thread Mike Bayer
On 07/21/2016 01:44 PM, Simon King wrote: On Thu, Jul 21, 2016 at 5:58 PM, Jonathan Vanasco wrote: On Thursday, July 21, 2016 at 12:15:40 PM UTC-4, Simon King wrote: There are some hints for keeping references to objects at:

Re: [sqlalchemy] Leveled single table inheritance without declarative API

2016-07-24 Thread Mike Bayer
On 07/25/2016 12:23 AM, Ameretat Reith wrote: mapper(Father1980,fathers,inherits=fathersMapper, polymorphic_identity='young-father') you have the wrong table above ("fathers" and not "fathers80s"). There's a bug here in how the ORM is corrupting the table in response to this which

Re: [sqlalchemy] Delegating to _declarative_constructor

2016-07-25 Thread Mike Bayer
On 07/25/2016 09:12 AM, Michael Williamson wrote: Hello! For one of our models, I've defined a custom implementation for `__init__`. Since it should largely behave the same as the default constructor, it delegates to `_declarative_constructor`, and then runs some extra code. However, this

Re: [sqlalchemy] Understanding behavior of association_proxy

2016-07-24 Thread Mike Bayer
On 07/24/2016 07:57 PM, Eric Wittle wrote: I'd like to understand the behavior of association_proxy when creating new records across a many-to-many table where, in some cases, the joining table will have additional attribute values beyond the two primary keys. In the below example, there is a

Re: [sqlalchemy] Leveled single table inheritance without declarative API

2016-07-24 Thread Mike Bayer
On 07/23/2016 01:34 PM, Ameretat Reith wrote: I'm trying to make three `Guy', `Father' and `Father1980' models mapped to two `guys' and `fathers' tables. Fathers will inherit Guys and Father1980 will inherit Fathers. So I coded it as: | fromsqlalchemy

Re: [sqlalchemy] SQLAlchemy 1.1b2 TypeError: the JSON object must be str, not 'bytes' with mysql 5.7.12 and JSON field type

2016-07-24 Thread Mike Bayer
this mostly appears to be a pymysql issue (string values should be decoded, mysqlclient acts correctly) so I've reported it at https://github.com/PyMySQL/PyMySQL/issues/488 I'd install mysqlclient for now. Hopefully pymysql can respond if they'll fix this in time for SQLA 1.1 final.

Re: [sqlalchemy] refresh_flush is not triggered when only the primary key is updated

2016-07-29 Thread Mike Bayer
Thanks for the great test case and this would be appropriate to be posted as a bug, since it is a complete description. So, the reason the primary key is not included right now is because primary keys are populated in many different ways on the object, meaning if your code relies upon

Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-07-29 Thread Mike Bayer
you might need to change more than this, but at least the fundamental thing about @expression is that it has to return a column, not a Query or a select(). On either one, calling as_scalar() will give you a scalar subquery, e.g. a SELECT interpreted as a column. Assuming there's still

Re: [sqlalchemy] Parameter injection issue upon db engine creation (tested with db2)

2016-07-29 Thread Mike Bayer
Hello - This issue is specific to the workings of the dialect, in that it is concatenating the URL components into a single string for the DBAPI connect function. As ibm_db_sa is not part of SQLAlchemy, you'd need to report this issue to them. However, the same technique you refer to here

Re: [sqlalchemy] relationship with DeferredReflection raises NoForeignKeysError

2016-07-29 Thread Mike Bayer
name the COUNTRY_ID column in lower case in your mapping, all UPPERCASE means case sensitive and it will be quoted "COUNTRY_ID", and not match the case-insensitive country_id name in your actual schema. On 07/29/2016 03:29 PM, bsdz wrote: I did some further checking and realized deeper down

Re: [sqlalchemy] Re: Understanding behavior of association_proxy

2016-07-29 Thread Mike Bayer
On 07/29/2016 06:39 PM, Eric Wittle wrote: I don't have sqlite installed, so I skipped actually creating the engine, all Python versions have sqlite3 included in the distribution itself unless you're on Jython (which I doubt works with SQLA these days)? | fromsqlalchemy

Re: [sqlalchemy] Default behavior for sqlalchemy_utils.UUIDType

2016-07-30 Thread Mike Bayer
On 07/29/2016 09:45 PM, Jason Libbey wrote: Hi, this is my first post, so if it does not adhere by your guidelines, please let me know and I'll fix it ASAP. I'm using the sqlalchemy_utils.UUIDType as per backend-agnostic-guid-type

[sqlalchemy] Alembic 0.8.7 released

2016-07-26 Thread Mike Bayer
Alembic 0.8.7 is now available. This release features a series of fixes to the versioning system that allow a greater degree of flexibility in version movement across branches with cross-dependencies, particularly within downgrades. Changelog is at:

[sqlalchemy] SQLAlchemy 1.1.0b3 Released

2016-07-26 Thread Mike Bayer
SQLAlchemy release 1.1.0b3 is now available. This is likely the last beta of the 1.1 series, which repairs a few issues in the new CTE for UPDATE/INSERT feature. Overall not many regressions or issues have been reported in the beta series, however this is typical; once the 1.1 final release

Re: [sqlalchemy] Implementation of params for textual SQL prevents its use in column names (use Python format as workaround)

2016-07-27 Thread Mike Bayer
On 07/27/2016 10:11 PM, Andrew M wrote: FYI, there seems to be a limitation of the implementation of params for textual SQL - params appears to silently insert single quotes, preventing the use of params to describe column names in the SQL query. that's SQL . Bound parameters are not Python

Re: [sqlalchemy] Associating select columns to original tables

2016-07-27 Thread Mike Bayer
On 07/27/2016 05:29 PM, T Johnson wrote: I am generating select queries that include alias tables, literal columns, renamed columns via label, multiple joins etc. The queries can be somewhat complex and as a debugging feature, I'd like be able to know which columns came from which

Re: [sqlalchemy] Inner Joins in sqlalchemy example?

2016-07-27 Thread Mike Bayer
On 07/26/2016 04:13 PM, Lukasz Szybalski wrote: Hello, I'm trying to make this inner join in sqlalchemy. MSSql. Is there an example of this? or a guide how to reproduce this. AutoLoad All tables. I need to know how to create this in sqlalchemy, then I'm going to loop the csv file with 1000

Re: [sqlalchemy] Re: orm add() or table insert() without implicit_returning

2016-08-10 Thread Mike Bayer
also, INSERT without ever needing a SELECT definitely implies you don't need an ORM. Use Core directly. On 08/10/2016 12:40 PM, mdob wrote: Me again. Just wanted to say that | engine =create_engine(connstr,implicit_returning=False,use_scope_identity=True,echo=True) | actually works as

Re: [sqlalchemy] Joining tables across schema in PostgreSQL

2016-08-10 Thread Mike Bayer
On 08/10/2016 12:06 PM, Demitri Muna wrote: There's nothing like hitting a brick wall of a problem that you definitively solved years ago. Right before any of these statements I print FitsFile.__table__.foreign_key_constraints and get the wall of text below where I *do* see the foreign key

Re: [sqlalchemy] refresh_flush is not triggered when only the primary key is updated

2016-08-02 Thread Mike Bayer
event = do another flush); it will stop after 100 loops around to prevent this. So you'd need to make sure your routine has no chance of going into an endless loop. On Friday, July 29, 2016 at 5:35:01 PM UTC+3, Mike Bayer wrote: Thanks for the great test case and this would

Re: [sqlalchemy] Re: DBAPI Error with SQLAlchemy-1.0.5

2016-08-02 Thread Mike Bayer
I'd recommend trying psycopg2 as the driver as it may handle this failure mode more gracefully. On 08/02/2016 04:34 AM, Simon King wrote: It looks like an exception is occurring, which SQLAlchemy has caught and is now trying to roll back the transaction before re-raising the initial

Re: [sqlalchemy] refresh_flush is not triggered when only the primary key is updated

2016-08-02 Thread Mike Bayer
bject after flush" event, if you can limit your criteria to objects that had a state change. But building a loop in after_flush() is easy enough. On Tuesday, August 2, 2016 at 4:37:19 PM UTC+3, Mike Bayer wrote: On 08/02/2016 04:24 AM, Lenar Imamutdinov wrote: &

Re: [sqlalchemy] Re: subqueryload with multiple joined table inheritance hierarchies

2016-08-11 Thread Mike Bayer
On 08/11/2016 09:53 AM, Douglas Russell wrote: of_type was what I was searching for. Thanks. Unfortunately, it did not yield the desired results when I extended the hierarchy to 3 levels (C->C2 with a relation between B and C). I've updated the Gist. B+B2 is successfully queried, but C+C2

Re: [sqlalchemy] Tracking instance commit status

2016-08-11 Thread Mike Bayer
On 08/11/2016 03:30 AM, Wibowo Arindrarto wrote: Dear all, I have a little problem with getting object states that have been flushed but not committed. As far as I understand, SQLAlchemy does not have an official object state corresponding to this. The Session is intended to only be working

Re: [sqlalchemy] Joining tables across schema in PostgreSQL

2016-08-11 Thread Mike Bayer
On 08/11/2016 01:24 PM, Demitri Muna wrote: Hi Mike, It looks like my Base class was not exactly the same (although it was in my original code), but this is not the problem. I didn't think it was, but it's very difficult for me to be helpful when I only get various out of context lines of

Re: [sqlalchemy] Re: subqueryload with multiple joined table inheritance hierarchies

2016-08-11 Thread Mike Bayer
ursday, 11 August 2016 11:51:39 UTC-4, Mike Bayer wrote: On 08/11/2016 09:53 AM, Douglas Russell wrote: > of_type was what I was searching for. Thanks. > > Unfortunately, it did not yield the desired results when I extended the > hierarchy to 3 levels (C->C

Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-08-03 Thread Mike Bayer
OK first problem is, the SQL you showed me is: select ( select (array_agg(unwave.restw)) as restwarr from ( select ( unnest(w.wavelength)/(1+n.z)) as restw from mangadatadb.wavelength as w ) as unwave ) from mangadatadb.cube as c join

Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-08-03 Thread Mike Bayer
There is still much ambiguity here and inaccuracy (JOINs on the outside or JOINs on the inside, the mappings have mistakes like foreign key to "pk" but no "pk", mappings without primary keys, "autoload" makes no sense as I don't have your tables, etc.), so I can only guess but perhaps give you

Re: [sqlalchemy] Relationship with query time evaluated primaryjoin

2016-08-04 Thread Mike Bayer
On 08/04/2016 10:14 AM, Florian Rüchel wrote: I have a relationship that depends on a query time variable to determine the correct join. The use case is request-time localization in a web application. When running the query during a request, I want to determine the locale and only load the

Re: [sqlalchemy] Updates with GROUP BY and subquery

2016-08-12 Thread Mike Bayer
build an update out of abms_biog: stmt = update(abms_biog) use prefixes to get the "ignore" part: stmt = stmt.prefix_with("ignore", dialect="mysql") make sure your subquery is a Core selectable: subq = my_orm_query.subquery() add your subquery to the WHERE clause. e.g. the JOIN keyword

Re: [sqlalchemy] deleted to detached state in nested transaction on session

2016-08-10 Thread Mike Bayer
On 08/10/2016 09:01 PM, Frazer McLean wrote: SQLAlchemy v1.1b3 on Python 3.5.2 Is it expected behaviour that in this MVCE the deleted object does not become detached after the final commit? The term "final commit" is misleading here since that's not a transaction COMMIT, that's just a

Re: [sqlalchemy] Joining tables across schema in PostgreSQL

2016-08-10 Thread Mike Bayer
On 08/10/2016 09:01 PM, Demitri Muna wrote: Hi Mike, I think I'm more perplexed than before. My search_path was correctly set. I put a breakpoint in my code after all of my classes and relationships are defined and after a call to configure_mappers(). that doesn't make sense because the

Re: [sqlalchemy] Updates with GROUP BY and subquery

2016-08-12 Thread Mike Bayer
elect() somewhere? Thanks once again for your time. On Friday, August 12, 2016 at 7:07:19 AM UTC-7, Mike Bayer wrote: build an update out of abms_biog: stmt = update(abms_biog) use prefixes to get the "ignore" part: stmt = stmt.prefix_with("ignore", diale

Re: [sqlalchemy] Implicit join condition

2016-07-13 Thread Mike Bayer
d q = q.join(subquery_returning_one_id, subquery_returning_one_id.c.id == joining_to) return q On Wednesday, July 13, 2016 at 12:16:52 PM UTC-4, Mike Bayer wrote: On 07/13/2016 02:29 AM, Seth P wrote: > [Apologies for posting an incomplete version of this post earli

Re: [sqlalchemy] Implicit join condition

2016-07-13 Thread Mike Bayer
subquery_returning_one_id.c.id onclause = visitors.replacement_traverse(onclause, {}, replace) q = q.join(subquery_returning_one_id, onclause) return q On Wednesday, July 13, 2016 at 2:06:55 PM UTC-4, Mike Bayer wrote: On 07/13/2016 01:04 PM, Seth P wrote: > Thank you, as alw

Re: [sqlalchemy] How to get unambiguous column name for selectable?

2016-07-21 Thread Mike Bayer
On 07/21/2016 10:09 AM, Andrew Pashkin wrote: On 07/15/2016 04:14 PM, Mike Bayer wrote: I wasn't sure what the question was here. To get the first ORM entity, use column_descriptions: query = query.order_by(query.column_descriptions[0]["entity"].name) Are entities in column_de

Re: [sqlalchemy] automap_base from MySQL doesn't setup all tables in Base.classes but they are in metadata.tables

2016-07-20 Thread Mike Bayer
On 07/20/2016 04:44 PM, bkcsfi sfi wrote: I have a legacy MySQL database that I am working with sqla version 1.0.11 and MySQL-Python engine (just upgraded to 1.0.14, problem persists) I use automap_base and prepare with reflect=True some of the tables in this database are association tables.

Re: [sqlalchemy] Postgres not(any_) issue within recursive CTE

2016-07-20 Thread Mike Bayer
On 07/20/2016 07:53 PM, cledo...@twistbioscience.com wrote: Hi, I'm very glad to see the any_ operator fully supported in SqlAlchemy 1.1b2. We'd like to use this operator to implement an efficient recursive CTE (RCTE) that avoids cycles. One way to get an RCTE to avoid cycles is to maintain

Re: [sqlalchemy] Problem with 'fetchone'

2016-07-18 Thread Mike Bayer
On 07/18/2016 12:15 PM, Tian JiaLin wrote: Hi Everyone, I have been using MySQL-Python for a long time. Recently I tried to integrated a connection pool which is based on SQLAlchemy, In terms of the legacy code, I'm using the raw_connection from the engine. Here is the sample code of two

Re: [sqlalchemy] Error IM001 reflecting table

2016-07-19 Thread Mike Bayer
On 07/19/2016 04:50 AM, Angelo Bulone wrote: first of all, sorry if I'm not writing in the right place or I'm not providing enough info about the issue. Using SQL Alchemy, with pyodbc. I'm trying to reflect a table. When I try to do that, i get this message DBAPIError: (pyodbc.Error)

Re: [sqlalchemy] Detecting relationship conflicts

2016-07-19 Thread Mike Bayer
On 07/19/2016 08:52 AM, Burak Arslan wrote: Hi, Behold this test: https://github.com/plq/spyne/blob/be189784b02e204b031f25bc748d9236ef7dfc59/spyne/test/test_sqlalchemy.py#L314 This is for Spyne => SQLAlchemy object bridge so please ignore Spyne-specific stuff in there. I noticed that this

Re: [sqlalchemy] Combining yield_per and eager loading

2016-07-19 Thread Mike Bayer
On 07/19/2016 12:33 PM, Martijn van Oosterhout wrote: On Sunday, July 17, 2016 at 8:47:11 AM UTC+2, Martijn van Oosterhout wrote: I'll play a bit and see what I can get to work. Thanks again. So, I have a chance to play and got something that actually works quite nicely, see below. Two

Re: [sqlalchemy] SAWarning shows not immediately, but after some time of app execution

2016-07-19 Thread Mike Bayer
On 07/19/2016 11:51 AM, TomS. wrote: Hi, We have Flask app which uses SQLAlchemy. Weird error started to happen recently. The difficulty is that we can't reproduce the error (/figure out conditions causing issue) - maybe someone could help. Any hints/tips would be appreciated. There is a

Re: [sqlalchemy] Detecting relationship conflicts

2016-07-19 Thread Mike Bayer
On 07/19/2016 01:37 PM, Burak Arslan wrote: On 07/19/16 20:19, Burak Arslan wrote: On 07/19/16 19:38, Mike Bayer wrote: this warning will be removed in 1.1, see https://bitbucket.org/zzzeek/sqlalchemy/issues/3749 That's nice but am I to understand there is no easy way to test this? I

Re: [sqlalchemy] Combining yield_per and eager loading

2016-07-19 Thread Mike Bayer
On 07/19/2016 05:20 PM, Martijn van Oosterhout wrote: On 19 July 2016 at 18:42, Mike Bayer <mike...@zzzcomputing.com <mailto:mike...@zzzcomputing.com>> wrote: On 07/19/2016 12:33 PM, Martijn van Oosterhout wrote: On Sunday, July 17, 2016 at 8:47:11 AM UTC+2,

Re: [sqlalchemy] How to get unambiguous column name for selectable?

2016-07-15 Thread Mike Bayer
I wasn't sure what the question was here. To get the first ORM entity, use column_descriptions: query = query.order_by(query.column_descriptions[0]["entity"].name) http://docs.sqlalchemy.org/en/latest/orm/query.html?highlight=column_descriptions#sqlalchemy.orm.query.Query.column_descriptions

Re: [sqlalchemy] Rolling back the session in a context manager

2016-07-15 Thread Mike Bayer
On 07/15/2016 07:49 AM, Alex Grönholm wrote: The documentation provides the following example snippet for using sessions within a context manager: so, back when I started putting "examples" in those docs, the idea was like, "hey, here's an *example*. The Python programmer is free to do

Re: [sqlalchemy] Combining yield_per and eager loading

2016-07-15 Thread Mike Bayer
On 07/15/2016 12:08 PM, Martijn van Oosterhout wrote: Ok, so SQLAlchemy has this nice feature where you can eager load relationships to significantly reduce the number of queries during processing. On the other hand, to reduce memory usage you can use yield_per() (on Postgres) to

Re: [sqlalchemy] Combining yield_per and eager loading

2016-07-15 Thread Mike Bayer
On 07/15/2016 05:14 PM, Martijn van Oosterhout wrote: On 15 July 2016 at 18:46, Mike Bayer <mike...@zzzcomputing.com <mailto:mike...@zzzcomputing.com>> wrote: Here's the problem that cant be solved: 1. fetch rows 0-1000 2. start loading Foo objects:

Re: [sqlalchemy] Specify query_cls for the one query

2016-07-11 Thread Mike Bayer
Query takes the Session as an argument so you should be able to say: q = MyQuery([MyModel], session=my_session) On 07/11/2016 03:23 PM, Антонио Антуан wrote: Can I specify query_cls only for a one query? I try to change query.session._query_cls and, of course, it doesn't work... I want to

Re: [sqlalchemy] with_session and subquery loading

2016-06-28 Thread Mike Bayer
On 06/28/2016 10:39 AM, Michael Williamson wrote: On Tuesday, June 28, 2016 at 2:57:08 PM UTC+1, Mike Bayer wrote: On 06/28/2016 05:28 AM, mic...@healx3.com wrote: > Hello! I sometimes find it more convenient to create to construct a > query without a session, and then

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