Re: [sqlalchemy] filter like using a string in a column of timestamps without time zones - postgres

2018-09-11 Thread Simon King
On Tue, Sep 11, 2018 at 9:39 AM George Brande wrote: > > Hello. > > My angular is using a datepicker to send a date in string format(ex: > 2018-09-11) to my flask app to postgres via sqlalchemy. > In my postgres all rows have a column ef_time of timestamps type.(ex: > 2018-09-07 13:24:30.138) >

Re: [sqlalchemy] How to customize base declarative class to add naming conventions

2018-09-04 Thread Simon King
On Tue, Sep 4, 2018 at 3:48 PM wrote: > > I'd like to create a mixin to specify naming conventions. > > I tried both: > > class Base: > metadata = MetaData(naming_convention={ > "ix": "ix_%(column_0_label)s", > "uq": "uq_%(table_name)s_%(column_0_name)s", > "ck":

Re: [sqlalchemy] Re: Relationship to child with 2 foreginKey from same Parent column

2018-09-03 Thread Simon King
Here's a version which I *think* does what you want. There are a couple of things that you might want to note. First, in your paste, Conversation.user1 and Conversation.user2 are integer columns, but you are assigning User objects to those properties. That's not the way SQLAlchemy works - you

Re: [sqlalchemy] sqlalchemy session in same transaction as existing psycopg2 connection

2018-08-28 Thread Simon King
On Tue, Aug 28, 2018 at 5:53 PM Simon King wrote: > > On Tue, Aug 28, 2018 at 4:32 PM 'Brian DeRocher' via sqlalchemy > wrote: > > > > Hey all, > > > > I'm writing some automated tests for some legacy python code using a > > psycopg2 connection. I'd like

Re: [sqlalchemy] sqlalchemy session in same transaction as existing psycopg2 connection

2018-08-28 Thread Simon King
On Tue, Aug 28, 2018 at 4:32 PM 'Brian DeRocher' via sqlalchemy wrote: > > Hey all, > > I'm writing some automated tests for some legacy python code using a psycopg2 > connection. I'd like to check data in the database by using SQLAlchemy. I > rollback the database transaction after each test

Re: [sqlalchemy] Encoding troubles with pythong, mysql and utf8mb4

2018-08-22 Thread Simon King
. > > > On Wednesday, August 22, 2018 at 10:37:30 AM UTC+2, Simon King wrote: >> >> I've never used Pandas, so this may not make any sense, but where does >> the column "VARIABLE_VALUE" come from? Is it a column in your >> dataframe? >> >>

Re: [sqlalchemy] Encoding troubles with pythong, mysql and utf8mb4

2018-08-22 Thread Simon King
I've never used Pandas, so this may not make any sense, but where does the column "VARIABLE_VALUE" come from? Is it a column in your dataframe? Simon On Wed, Aug 22, 2018 at 8:52 AM wrote: > > I get the following warnings, when trying to save a simple dataframe to > mysql.: > > >

Re: [sqlalchemy] How to ignore primary key errors on insert

2018-08-21 Thread Simon King
If you are using SQLAlchemy core, there's this: http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#insert-on-conflict-upsert Does that meet your needs? Simon On Tue, Aug 21, 2018 at 3:36 AM Hardik Sanghavi wrote: > > Did this get resolved or are we to still ignore it > > > On

Re: [sqlalchemy] Re: Generic Associations - table_per_association: parent attribute

2018-07-30 Thread Simon King
You could build this, but it's going to be messy. At the SQL level, if you look at an Address row, there's not enough information to know which association table to look in. You'd have to query all of the association tables (perhaps using a UNION) to find the one that contains the parent, and then

Re: [sqlalchemy] So, Sqlalchemy migration tool is not support chang column type ?

2018-07-26 Thread Simon King
o generated is not use, how specify it. > > auto generated sql : ALTER TABLE invite_code ALTER COLUMN created_at TYPE > TIMESTAMP WITH TIME ZONE > > 在 2018年7月26日星期四 UTC+8下午6:16:10,Simon King写道: >> >> On Thu, Jul 26, 2018 at 11:03 AM Yingchen Zhang wrote:

Re: [sqlalchemy] So, Sqlalchemy migration tool is not support chang column type ?

2018-07-26 Thread Simon King
On Thu, Jul 26, 2018 at 11:03 AM Yingchen Zhang wrote: > > old model > > class User(db.Model): > __tablename__ = 'users' > id = db.Column(db.BigInteger, primary_key=True) > name = db.Column(db.VARCHAR(50), nullable=False) > > email = db.Column(db.VARCHAR(200), nullable=False) > >

Re: [sqlalchemy] M2M relationship back_populates KeyError

2018-07-02 Thread Simon King
On Mon, Jul 2, 2018 at 4:39 AM Juan wrote: > > Hi, > > I do not know if this is that I am missing something in how SQLAlchemy > works or an issue; I have read the doc and searched for an explanation > but could not find an answer. > > When appending via an intermediate table, a M2M relationship

Re: [sqlalchemy] three table join with confusing results

2018-06-01 Thread Simon King
What does the SQL look like for each of your queries? Can you produce a standalone script that demonstrates the problem? You could use my script from https://groups.google.com/forum/#!topic/sqlalchemy/GNIBQMvMRg8 as a template. Thanks, Simon On Fri, Jun 1, 2018 at 2:41 PM wrote: > > I'm

Re: [sqlalchemy] Re: Compare two schemas of two different DB's using Diff

2018-05-22 Thread Simon King
(Note that sqlalchemy-diff is not part of sqlalchemy, it's a tool built on top of it, and there may not be anyone on this list who has ever used it) Something like this might do what you want: from pprint import pprint from sqlalchemydiff import compare

Re: [sqlalchemy] Compare two schemas of two different DB's using Diff

2018-05-22 Thread Simon King
On Tue, May 22, 2018 at 12:03 PM, Neethu Abhinav wrote: > Hi, > > I have installed sqlalchemy 1.2.7, and went through the docs for sqlAlchemy > Diff, but i am still confused on how to use it effectively for my > requirement. > > We use Oracle 12C > > 1. We have two

Re: [sqlalchemy] Issue with Sqlalchemy in exe file(created using pyinstaller)

2018-05-22 Thread Simon King
com> wrote: > I tried --hidden-import sqlalchemy_teradata. It didnt help. Any way thanks > for the suggestion. > > On Wednesday, May 16, 2018 at 3:26:48 AM UTC-5, Simon King wrote: >> >> On Tue, May 15, 2018 at 8:59 PM, <bin...@gmail.com> wrote: >> &

Re: [sqlalchemy] polymorphic_on / polymorphic_identity randomly 'ignored'

2018-05-18 Thread Simon King
On Fri, May 18, 2018 at 12:19 PM, Benjamin B. wrote: > Hello everybody, > > TL;DR We are experiencing a bug where, with perfectly valid data, the > polymorphic_identity is randomly (0,05%) not respected, and the object > ends-up being the parent class instead of the "requested"

Re: [sqlalchemy] Issue with Sqlalchemy in exe file(created using pyinstaller)

2018-05-16 Thread Simon King
On Tue, May 15, 2018 at 8:59 PM, wrote: > I have been struggling for a few days due to an issue with SQLAlchemy. > > The line of code which is giving problem is > > engine = > sqlalchemy.create_engine('teradata://pwd@DBinstance?driver=Teradata') > > This code works perfectly

Re: [sqlalchemy] trying to retrieve data from multiple tables with .join()

2018-05-14 Thread Simon King
On Mon, May 14, 2018 at 9:37 AM, wrote: > Hi, I'm still relatively a newby to SQLAlchemy and not sure if I'm using the > correct query to achieve what I'm trying to and hoping someone can point me > in the correct direction or help me understand what I need to use to run the

Re: [sqlalchemy] Confused about Many-to-Many outerjoin

2018-05-01 Thread Simon King
On Tue, May 1, 2018 at 2:35 PM, wrote: > I'm using the PrettyPrinted tutorial on Many to Many relationships with > Flask-SQLAlchemy however what I'm trying to figure out he doesn't go into in > the tutorial and I haven't had much luck in _Essential SQLAlchemy_ or >

Re: [sqlalchemy] Re: Recursive Queries in SQLAlchemy (WITH clause/SEARCH BY depth/breadth)

2018-04-27 Thread Simon King
No, you'll need to convert that to the equivalent SQL. On Fri, Apr 27, 2018 at 3:14 PM, Jeremy Flowers <jeremy.g.flow...@gmail.com> wrote: > But can you still do things like slice(0,5)? Struggling to get that to work > atm... > > On Fri, Apr 27, 2018 at 2:48 PM, Simon King <s

Re: [sqlalchemy] Re: Recursive Queries in SQLAlchemy (WITH clause/SEARCH BY depth/breadth)

2018-04-27 Thread Simon King
On Fri, Apr 27, 2018 at 12:57 PM, Jeremy Flowers wrote: > Right... > Been trawling back thru this chain of exchanges.. > Looking for this: >> >> At this point I would echo Mike's question: why can't you just use >> "text()"? > > Just spotted another comment from Mike,

Re: [sqlalchemy] Re: Recursive Queries in SQLAlchemy (WITH clause/SEARCH BY depth/breadth)

2018-04-27 Thread Simon King
The ".first()" method applies the DB-specific equivalent of "LIMIT 1" to the query. Oracle apparently doesn't support the LIMIT keyword, so SQLAlchemy wraps the entire query in "SELECT ... FROM (subquery) WHERE ROWNUM <= limit":

Re: [sqlalchemy] Python Sqlalchemy filter by date range

2018-04-25 Thread Simon King
On Tue, Apr 24, 2018 at 4:49 AM, sum abiut wrote: > I have two date picker fields that i want the users to select from date to > end date. and i want to display data between the two dates that was > selected. From example form date: 2/14/2018 to date:3/15/2018. when the >

Re: [sqlalchemy] simple: get max id in table

2018-04-24 Thread Simon King
On Tue, Apr 24, 2018 at 4:43 PM, Steve Murphy wrote: > I'm just not getting it: > > Want: select max(id) from table; > > attempt (latest): > > from sqlalchemy import * > from sqlalchemy.engine import reflection > from sqlalchemy import schema > from sqlalchemy import exc >

Re: [sqlalchemy] Re: unable to do nested select while using query object

2018-04-19 Thread Simon King
Trying to diagnose a problem with a query when we don't have any way to run it for ourselves or sample data to run it against, is very difficult. If you want more help, I think you're going to need to produce a self-contained script with your table definitions and some sample data, that runs

Re: [sqlalchemy] Re: unable to do nested select while using query object

2018-04-18 Thread Simon King
r_name = ?' returned no > FROM clauses due to auto-correlation; specify correlate() to control > correlation manually. > > I am not sure how I should go about it. > > Thanks for your help, > > Greetings, > Sugandha > > On Wednesday, 18 April 2018 17:27:36 UTC+2, Simo

Re: [sqlalchemy] Re: unable to do nested select while using query object

2018-04-18 Thread Simon King
Are you executing q2 on it's own, or nested in a larger query? If so, can you show the code for the larger query. I ask because you are calling ".correlate(Partsupp, Supplier, Nation, Region)", which I think has the effect of removing those tables from the FROM clause, in the assumption that they

Re: [sqlalchemy] How to get ForeignKey from Relationship property

2018-04-11 Thread Simon King
On Wed, Apr 11, 2018 at 7:40 AM, Tolstov Sergey wrote: > I use dynamic constructor for class. > It works fine for instance who have not foreign keys. But when FK on another > instance it cannot load them > > Example: > class left (Base): > id = sqlalchemy.Column(UUID,

Re: [sqlalchemy] is this intentional or a bug with subquery join

2018-04-04 Thread Simon King
On Wed, Apr 4, 2018 at 4:08 AM, Jonathan Vanasco wrote: > > > On Tuesday, April 3, 2018 at 10:34:03 PM UTC-4, Mike Bayer wrote: >> >> "does not work" ? > > > wow, i am an awful person. sorry. that is the least helpful description of > what happens i can think of. > > second

Re: [sqlalchemy] rollback() practice

2018-03-29 Thread Simon King
On Thu, Mar 29, 2018 at 8:57 AM, wrote: > Hello, > > I had some database problems (unfinished transactions) so I have wrapped > sqlalchemy database handling functions in following way: > > def add(entry, session): > """Wrapper for db_session.add""" > try: >

Re: [sqlalchemy] Session's dialect's server_version_info may be None? (Execution order dependency)

2018-02-21 Thread Simon King
On Wed, Feb 21, 2018 at 6:14 AM, wrote: > Hello, > Suppose I create a db session the normal way: > engine = engine_from_config({"sqlalchemy.url":"mysql+pymysql://…"}) Session = sessionmaker(bind=engine) session = Session() > > I noticed that there is now an

Re: [sqlalchemy] How right use session/scoped_session in web app?

2018-02-16 Thread Simon King
OK, so what's not working? On Fri, Feb 16, 2018 at 10:55 AM, <eugene.de...@gmail.com> wrote: > Yes session.is_active is True. > I really sure, because i log this operation. > > пятница, 16 февраля 2018 г., 13:50:51 UTC+3 пользователь Simon King написал: >> >> You

Re: [sqlalchemy] How right use session/scoped_session in web app?

2018-02-16 Thread Simon King
> написал: >> >> You need just that: >> from proj.core import Session >> >> @app.teardown_request >> def clear_session(): >> Session.remove() >> >> Session created with scoper_session, of course. We do not use >> flask-sqlalchemy pack

Re: [sqlalchemy] How right use session/scoped_session in web app?

2018-02-15 Thread Simon King
gt; elif fetch == 'count': > return result > return result.fetchone() > > But same error. That variant must always close connection after return, but > problem in something another. > > > > четверг, 15 февраля 2018 г., 13:21:51 UTC+3 пользоват

Re: [sqlalchemy] How right use session/scoped_session in web app?

2018-02-15 Thread Simon King
been closed automatically. > But how it closed if that another session? > Can you correct my code? > > > > > среда, 14 февраля 2018 г., 17:45:59 UTC+3 пользователь Simon King написал: >> >> I think there are a couple of problems with this. >> >> 1. You are

Re: [sqlalchemy] Define one to one and many-to-many relationship using SQLAlchemy Core

2018-02-15 Thread Simon King
On Thu, Feb 15, 2018 at 5:09 AM, George wrote: > I have searched the documentation but didn't find anything useful. Please > guide me in the right direction. > I'm not sure I understand the question. Relationships are part of the ORM layer of SQLAlchemy, not Core. Can you

Re: [sqlalchemy] How right use session/scoped_session in web app?

2018-02-14 Thread Simon King
print('#FUNCTION NAME: {}'.format(func.__name__)) > > print(e) > logging.error(e) > return default > return wrapper > > > > > среда, 14 февраля 2018 г., 17:06:54 UTC+3 пользователь Simon King написал: >> >> T

Re: [sqlalchemy] How right use session/scoped_session in web app?

2018-02-14 Thread Simon King
The pattern you should be aiming for is one in which a fresh transaction is started for every web request that touches the database, and that the transaction is closed at the end of the request. How are you ensuring that at the moment? Simon On Wed, Feb 14, 2018 at 12:51 PM,

Re: [sqlalchemy] running py.test

2018-02-14 Thread Simon King
oth the libraries are surely > installed. > > > On Friday, 9 February 2018 12:36:26 UTC+1, Simon King wrote: >> >> On Wed, Feb 7, 2018 at 2:23 PM, su-sa <sachdeva@gmail.com> wrote: >> > Hallo everyone, >> > >> > I am trying to run all the

Re: [sqlalchemy] Re: Register function example (perhaps) to remove tab, newline or carriage return from column.

2018-02-14 Thread Simon King
On Fri, Feb 9, 2018 at 7:38 PM, Jeremy Flowers wrote: > And I do want to use this functionality repeatedly on many columns, hence > the idea of registering a function. > For what it's worth, I would do it something like this: def removechars(col, chars): for c in

Re: [sqlalchemy] Re: Why does join() method not have join type as an argument?/Is left-join the default..

2018-02-09 Thread Simon King
As you say, .join() produces an inner join by default. You can specify isouter=True to get a left outer join (or call the .outerjoin method instead), and full=True to get a full outer join. I think you'd get a cross join if you just didn't call the .join() method at all. Simon On Fri, Feb 9,

Re: [sqlalchemy] Re: Ways with SQLAlchemy ORM to get back some of the columns for a table

2018-02-09 Thread Simon King
(), I did this. >> print(session.query(Jobmst) >> .with_entities(Jobmst.jobmst_type, Jobmst.jobmst_name) >> .first() >> ) >> >> and that worked a treat too. >> Thanks. >> >> >> On Friday, 9 February 2018 11:58:18 UTC,

Re: [sqlalchemy] Re: Ways with SQLAlchemy ORM to get back some of the columns for a table

2018-02-09 Thread Simon King
The chaining-friendly method you are looking for is probably with_entities(): http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.with_entities Simon On Fri, Feb 9, 2018 at 11:52 AM, Jeremy Flowers wrote: > From watching your videos I

Re: [sqlalchemy] Re: Ways with SQLAlchemy ORM to get back some of the columns for a table

2018-02-09 Thread Simon King
The main point you should take from Mike's original reply is: .values() is a weird method and it's pretty old, usually people just set the columns up front You probably shouldn't use it. On Fri, Feb 9, 2018 at 11:45 AM, Jeremy Flowers wrote: > Also this didn't

Re: [sqlalchemy] Query a query in SQLAlchemy

2018-02-09 Thread Simon King
On Fri, Feb 9, 2018 at 6:06 AM, Charles Heizer wrote: > Hello, does anyone know if it's possible to query a query result in > SQLAlchemy? > > Thanks! > I'm not quite sure what you mean. If you've got a Query object with some filter conditions already defined, you can add

Re: [sqlalchemy] running py.test

2018-02-09 Thread Simon King
On Wed, Feb 7, 2018 at 2:23 PM, su-sa wrote: > Hallo everyone, > > I am trying to run all the pytest of sqlalchemy. But I always get the error > - SQLAlchemy requires Mock as of version 0.8.2. I already have the mock > library installed. Could somebody please help

Re: [sqlalchemy] MySQL's sql_mode (ORM)

2018-02-09 Thread Simon King
On Tue, Feb 6, 2018 at 7:08 PM, wrote: > If I were to go into my MySQL DB and > > mysql> SET GLOBAL sql_mode='STRICT_TRANS_TABLES'; > > would that have the same effect? I find the MySQL documentation somewhat > lacking on that topic. What are the scope and lifetime of the

Re: [sqlalchemy] Implementing historical tables

2018-02-01 Thread Simon King
On Wed, Jan 31, 2018 at 5:27 PM, Stanislav Lobanov wrote: > Hello, i need to create a system, that can store historical versions of > objects. > > Example model looks like: > > class User(Base): >id=Column(Integer) # ForeignKey >start=Column(DateTime) >

Re: [sqlalchemy] Re: Temporarily disable DB persistence for optimization routine

2018-01-15 Thread Simon King
age(satellite=self, > ground_station=ground_station, >aos=aos, los=los, tca=tca, >deltaT=deltaT) > > > `self` should be a reference to the instance of `Satellite` already loaded > from DB. I will try to div

Re: [sqlalchemy] About multithread session (scoped session)

2018-01-15 Thread Simon King
gt; Simon, > > Thanks for your kind answer. > So when I have several threads trying to insert/update the same database > (pgsql or sqlite) at the same time, how can I ensure consistency? By using > scoped session? This will rely on the DB implementation behind, right? > > 在 2018年1月15日星

Re: [sqlalchemy] Re: Temporarily disable DB persistence for optimization routine

2018-01-15 Thread Simon King
On Sat, Jan 13, 2018 at 3:31 PM, Ruben Di Battista <rubendibatti...@gmail.com> wrote: > > > On Friday, January 12, 2018 at 10:54:49 AM UTC+1, Simon King wrote: >> >> If I understand your code correctly, scheduler.propagate() creates a >> large number of Passage ins

Re: [sqlalchemy] Re: Temporarily disable DB persistence for optimization routine

2018-01-12 Thread Simon King
If I understand your code correctly, scheduler.propagate() creates a large number of Passage instances, and you only want a small subset of them to be added to the database. Is that correct? I would guess that the passages are getting added to the session because you are setting their 'satellite'

Re: [sqlalchemy] Polymorphic discriminator not being added to update queries

2018-01-11 Thread Simon King
On Thu, Jan 11, 2018 at 4:51 PM, Mischa S wrote: > In [6]: ClassificationTask.query.update(values={'completed': True}) > INFO [sqlalchemy.engine.base.Engine] base.py:679 BEGIN (implicit) > INFO [sqlalchemy.engine.base.Engine] base.py:1140 UPDATE schwartz_task > SET

Re: [sqlalchemy] Building relatively complex dynamic queries in SQLAlchemy

2018-01-03 Thread Simon King
On Tue, Jan 2, 2018 at 11:59 PM, Nikola Jankovic wrote: > I have an API endpoint that handles searches from the frontend. A search can > have a dynamic amount of filters applied to it, including (1) sizes, (2) > colors, (3) price, and (4) category that are passed through query

Re: [sqlalchemy] Help writing query - "where most recent is true, but any other is false"

2017-12-14 Thread Simon King
On Wed, Dec 13, 2017 at 10:24 PM, Leo Simmons wrote: > I have a table `special_product_list` and a table > `special_product_historical_details_list` that holds information of products > over time, where there's a record in the history table every day for every > product. > > I want

Re: [sqlalchemy] How to make polymorphic identity condition involving a join not be a subselect

2017-11-27 Thread Simon King
On Sun, Nov 26, 2017 at 11:19 AM, Mischa S wrote: > I want to have a polymorphic table that gets its identity from a column in a > "type" table. I have a "task" table and a "task_type" table. I want to be > able to create task subclasses that say something like: > >

Re: [sqlalchemy] Disable `session_identity_map` for `_instance_processor`

2017-11-23 Thread Simon King
On Thu, Nov 23, 2017 at 6:55 PM, Антонио Антуан wrote: > > > чт, 23 нояб. 2017 г. в 20:27, Mike Bayer : >> >> On Thu, Nov 23, 2017 at 8:44 AM, Антонио Антуан >> wrote: >> > >> >> A Query can have lots of entities in it, and if

Re: [sqlalchemy] Disable `session_identity_map` for `_instance_processor`

2017-11-23 Thread Simon King
On Thu, Nov 23, 2017 at 5:27 PM, Mike Bayer wrote: > On Thu, Nov 23, 2017 at 8:44 AM, Антонио Антуан wrote: >> >>> A Query can have lots of entities in it, and if you're doing sharding a >>> single result set can refer to any number of shard

Re: [sqlalchemy] Re: Required properties of first arg to bulk_insert_mappings

2017-11-21 Thread Simon King
I'm pretty sure that bulk_insert_mappings ends up just calling the same code that I suggested. What database are you using? If it's Postgres, you might be interested in http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#psycopg2-batch-mode (linked from

Re: [sqlalchemy] Re: Required properties of first arg to bulk_insert_mappings

2017-11-21 Thread Simon King
(TLDR: I think bulk_insert_mappings is the wrong function for you to use) SQLAlchemy consists of 2 main layers. The Core layer deals with SQL construction, database dialects, connection pooling and so on. The ORM is built on top of Core, and is intended for people who want to work with "mapped

Re: [sqlalchemy] Confusion over session.dirty, query, and flush

2017-11-16 Thread Simon King
; > On Thursday, November 16, 2017 at 7:49:54 PM UTC+10, Simon King wrote: >> >> On Thu, Nov 16, 2017 at 7:45 AM, <jens.t...@gmail.com> wrote: >> > Hello, >> > >> > I've been exploring some of the session functionality that handles &

Re: [sqlalchemy] Confusion over session.dirty, query, and flush

2017-11-16 Thread Simon King
On Thu, Nov 16, 2017 at 7:45 AM, wrote: > Hello, > > I've been exploring some of the session functionality that handles object > states, and I'm quite confused. Here is what I see: > engine = engine_from_config({'sqlalchemy.url': 'mysql+pymysql://…'})

Re: [sqlalchemy] Two classes linked to the same backref attribute in a third classe

2017-11-15 Thread Simon King
On Wed, Nov 15, 2017 at 12:10 AM, Mike Bayer wrote: > On Tue, Nov 14, 2017 at 2:58 PM, Olaf wrote: >> Hello everybody. >> >> Is it possible to have the following relationships between three classes >> (Animal, Car, Description) ? >> >> * An animal

Re: [sqlalchemy] SQLAlchemy leaves MySQL open connections

2017-11-13 Thread Simon King
On Mon, Nov 13, 2017 at 4:35 PM, Ahmad Javed wrote: > Thank you Simon. Appreciate your response. Just using session.remove() at > the end of each request is not closing the connection and leave open > connections in MySQL database. One more thing I want to tell that we

Re: [sqlalchemy] SQLAlchemy leaves MySQL open connections

2017-11-13 Thread Simon King
On Mon, Nov 13, 2017 at 3:58 AM, Ahmad Javed wrote: > Hi, > > We have implemented web applications using Django and SQLAlchemy framework. > We have distributed system in the company and some API used frequently. > > We are facing a problem where MySQL connections reached

Re: [sqlalchemy] Excluding attributes from polymorphic hierarchy

2017-10-27 Thread Simon King
On Fri, Oct 27, 2017 at 4:57 PM, wrote: > My SQLAlchemy version is 1.1.14. > > I'm having difficulty understanding behaviours around a polymorphic > hierarchy. > > I have an AbstractConcreteBase and two subclasses. > > The ACB declares some attributes shared by the two

Re: [sqlalchemy] mapper existance checks possibly wrong

2017-10-25 Thread Simon King
gt;: >> >> As I mentioned before, "> group_getter>". >> >> ср, 25 окт. 2017 г. в 14:19, Simon King <si...@simonking.org.uk>: >>> >>> What does self._mapper_zero() return in your >>> RoutingQuery._execute_and_instances metho

Re: [sqlalchemy] mapper existance checks possibly wrong

2017-10-25 Thread Simon King
писал: >> >> I see that it is not happened when "bind" passed directly to >> "sessionmaker" >> >> сб, 21 окт. 2017 г. в 18:33, Антонио Антуан <a.ch@gmail.com>: >>> >>> >>> >>> пятница, 20 октября 2017 г.,

Re: [sqlalchemy] mapper existance checks possibly wrong

2017-10-20 Thread Simon King
> > I use: >>>> sqlalchemy.__version__ > '1.0.19' > > пятница, 20 октября 2017 г., 16:42:23 UTC+3 пользователь Simon King написал: >> >> On Fri, Oct 20, 2017 at 2:15 PM, Антонио Антуан <a.ch...@gmail.com> wrote: >> > Hi. >> > I use

Re: [sqlalchemy] mapper existance checks possibly wrong

2017-10-20 Thread Simon King
On Fri, Oct 20, 2017 at 2:15 PM, Антонио Антуан wrote: > Hi. > I use my own `RoutingSession` and `RoutingQuery` implementation, most of it > inspired by `sqlalchemy.ext.horizontal_shard`: > > class RoutingSession(Session): > def get_bind(self, mapper=None, clause=None,

Re: [sqlalchemy] SQLAlchemy enum in external file

2017-10-20 Thread Simon King
On Thu, Oct 19, 2017 at 9:10 PM, TazMainiac wrote: > > > On Thu, Oct 19, 2017 at 2:25 PM, Jonathan Vanasco > wrote: >> >> On Thursday, October 19, 2017 at 11:55:49 AM UTC-4, Taz Mainiac wrote: >>> >>> So - a morning spent googling does not turn up any

Re: [sqlalchemy] Postgres database: open and close connection

2017-10-06 Thread Simon King
On Fri, Oct 6, 2017 at 9:59 AM, Martin Cigorraga wrote: > Hi, > > I'm trying to create a simple function to check the reachability of a > Postgres database using the http method GET; if the connection can't be > established, it should respond with a custom http error

Re: [sqlalchemy] sqlalchemy foreignkey relation with inheritance

2017-09-22 Thread Simon King
On Fri, Sep 22, 2017 at 9:42 AM, Simon King <si...@simonking.org.uk> wrote: > On Fri, Sep 22, 2017 at 8:18 AM, John Smith <johnsmith31...@gmail.com> wrote: >> I have the following database schema: >> >> Table "Parent": >> 1. id - primary key id

Re: [sqlalchemy] sqlalchemy foreignkey relation with inheritance

2017-09-22 Thread Simon King
On Fri, Sep 22, 2017 at 8:18 AM, John Smith wrote: > I have the following database schema: > > Table "Parent": > 1. id - primary key identifier. > 2. type - polymorphic_identity. > 3. name - string data column. > > Table "Child" - inherits Parent: > 1. id - primary key

Re: [sqlalchemy] A "after flush before commit" event

2017-09-15 Thread Simon King
Could you pair a before_commit handler with an after_flush_postexec handler? The before_commit one would set a flag to say that you are committing, and the after_flush_postexec one would look for that flag before proceeding. Simon On Fri, Sep 15, 2017 at 12:08 AM, wrote: >

Re: [sqlalchemy] Multiple front end server with Single MySQL database

2017-09-14 Thread Simon King
On Thu, Sep 14, 2017 at 12:07 PM, Ankur Kumar wrote: >> I'm reallly sorry. > > > Please also update line number 13 in api.py and api1_py as > > old : > output = session.query(model.Bug_Test.value).with_for_update('read').all() > > New: > output =

Re: [sqlalchemy] Multiple front end server with Single MySQL database

2017-09-14 Thread Simon King
On Thu, Sep 14, 2017 at 10:59 AM, Ankur Kumar wrote: >> Hello Simon, > > > Thanks, > I donot want to read uncommitted data. > > I want to read committed data by one API server from another API server. >> >> > > From another API server it keeps showing old data > Ah,

Re: [sqlalchemy] Multiple front end server with Single MySQL database

2017-09-14 Thread Simon King
On Thu, Sep 14, 2017 at 10:03 AM, Ankur Kumar wrote: > I'm using Flask, sqlalchemy with MySQL database for my API server. > > It's working fine with one front end API server. > But now i want to increase a front end API server in my Load balancer. > > So, the scenario

Re: [sqlalchemy] Is Textual SQL DB neutral

2017-08-31 Thread Simon King
I'm pretty sure the bad performance is due to pyodbc (or maybe SQL Server) not handling *huge* numbers of bind parameters gracefully. You are generating a query with (batch_size * n_primary_key_columns) bind parameters, which even in your original version meant 2000 bind parameters. Try with a

Re: [sqlalchemy] Is Textual SQL DB neutral

2017-08-31 Thread Simon King
ld = 'value' > syntax? > > On Wednesday, August 30, 2017 at 12:07:52 PM UTC-4, Simon King wrote: >> >> You could also try using executemany: >> >> >> http://docs.sqlalchemy.org/en/latest/core/tutorial.html#executing-multiple-statements >> >> I think it would look

Re: [sqlalchemy] Is Textual SQL DB neutral

2017-08-30 Thread Simon King
h > contains description text. > > Total record count of the table before any deletion is about 1.05 million. > > Python version is 3.4.5, running on a modest CentOS desktop and to be fair > the SQL Server instance is sub optimal for development. > > On Wednesday, August 30, 201

Re: [sqlalchemy] Is Textual SQL DB neutral

2017-08-30 Thread Simon King
55620.0300.0000.1870.000 result.py:1156(fetchone) > 111310.0300.0000.0770.000 compiler.py:494() > 111230.0290.0000.0470.000 > type_api.py:452(_cached_bind_processor) > > Any guidance to how I can improve the performance of this so

Re: [sqlalchemy] Is Textual SQL DB neutral

2017-08-30 Thread Simon King
On Tue, Aug 29, 2017 at 9:49 PM, Ken MacKenzie wrote: > I have a query I have constructed and I had to deal with a composite primary > key to select items; > > q = s.query(cls) > or_cond = [] > for x in id_batch: > > pkf =

Re: [sqlalchemy] SQLAlchemy 1.1 cause core dump committing multiple dirty records outside of function where mutation happens

2017-08-22 Thread Simon King
On Tue, Aug 22, 2017 at 9:26 AM, Konstantin Kashin wrote: > # Setup > Suppose I have a table with two fields: a string primary key and a boolean > flag. I want to query multiple rows and then update the flag across all of > them, then commit my changes. I have a MySQL DB with

Re: [sqlalchemy] How do I get an object and update multiple fields in sqlalchemy

2017-08-21 Thread Simon King
ms(): > setattr(obj, key, value) > > > On Friday, 18 August 2017 19:47:50 UTC+5:30, Simon King wrote: >> >> No, but you can trivially write your own function to do it: >> >> def updateobj(obj, data): >> for key, value in data.items(): >> set

Re: [sqlalchemy] How do I get an object and update multiple fields in sqlalchemy

2017-08-18 Thread Simon King
ut I have a dict of keys to be > updated with that get instance. Is there any specific way of updating > something like product_live_time_instance.update(data_dict). > > > On Friday, 18 August 2017 19:21:12 UTC+5:30, Simon King wrote: >> >> On Fri, Aug 18, 2017 a

Re: [sqlalchemy] How do I get an object and update multiple fields in sqlalchemy

2017-08-18 Thread Simon King
On Fri, Aug 18, 2017 at 2:41 PM, pravin battula wrote: > Hi, > > I'm getting an instance of a model using a primary key like below. > product_live_time = session.query(ProductLiveTime).get(product_id) > > Now, i want to update few columns using the same instance

Re: [sqlalchemy] Raising on usage of attribute in SQL queries

2017-08-17 Thread Simon King
On Thu, Aug 17, 2017 at 12:35 AM, Neena Parikh wrote: > Hi there! > > I'm looking to create a helper or decorator function that will enable us to > "mark" a column or table as “unused”, and raise an error if that column or > table is queried for in SQL. > > > Context > The

Re: [sqlalchemy] Guidance for mapping tables dynamically

2017-07-31 Thread Simon King
On Fri, Jul 28, 2017 at 12:44 AM, Saurabh Bhandiwad wrote: > Hello experts, > > Apologies if this question has been asked before, I couldn't find the right > question on internet which reflects my problem. > > In my project i receive SQLITE file and I need to query

Re: [sqlalchemy] Is there a way to configure session.commit() so that it automatically return the committed instance's class.__name__ + primary id?

2017-07-25 Thread Simon King
On Tue, Jul 25, 2017 at 2:35 AM, Jinghui Niu wrote: > I was wondering if there is a way to configure Session.commit() so on each > successful commit, it will return the committed/updated/deleted instance's > class.__name__ + row.id. Is this possible? Thanks. No, there's no

Re: [sqlalchemy] SQLAlchemy won't connect correctly but pyodbc and pymssql will

2017-07-04 Thread Simon King
The key part of the stack trace is: File "c:\Program Files\Anaconda2\lib\site-packages\sqlalchemy\dialects\mssql\base.py", line 1773, in _get_default_schema_name default_schema_name = connection.scalar(query) ...which is in this function:

Re: [sqlalchemy] Optimize SQLAlchemy query

2017-06-30 Thread Simon King
On Fri, Jun 30, 2017 at 12:44 PM, mvidalgarcia wrote: > Hi, I'm performing a query to some data models but the ORM response time > looks much higher compared to the SQL one. I have a script to reproduce the > problem here. > Currently getting values like > >> sql time:

Re: [sqlalchemy] execute Stored procedure.

2017-06-28 Thread Simon King
On Wed, Jun 28, 2017 at 6:39 AM, Vigneshrajan wrote: > Is it is possible to execute stored procedure in connection.execute() > function? > I think it depends on the stored procedure. Do any of these search results help?

Re: [sqlalchemy] Re: Wierdness with JSONB / Python dictionary

2017-06-28 Thread Simon King
On Wed, Jun 28, 2017 at 1:35 AM, Andrew M wrote: > I can also replicate it with JSON, with a table defined as follows: > > class Test(Base): > __tablename__ = 'test' > id = Column(INT, primary_key=True, index=True) > json = Column(JSON, default={}) > > And

Re: [sqlalchemy] Re: How to do scalar sub selects with the ORM correctly?

2017-06-15 Thread Simon King
You might be interested in this thread: https://groups.google.com/forum/#!msg/sqlalchemy/8z0XGRMDgCk/tazeIUsdDgAJ Simon On Thu, Jun 15, 2017 at 1:53 PM, 'mike waites' via sqlalchemy wrote: > Interestingly I've just discovered the concept of Bundles. >

Re: [sqlalchemy] Adding filters to association (secondary) relationships

2017-06-15 Thread Simon King
secondary="join(user_team_association, > user_team_association.c.is_manager==true)", > backref="managers") > > seems to be an incomplete join. I’ll look into this tomorrow… > Jens > > > On Thursday, June 15, 2017 at

Re: [sqlalchemy] Adding filters to association (secondary) relationships

2017-06-15 Thread Simon King
Table objects put columns under the ".c" attribute, so you probably need "user_team_association.c.is_manager". Simon On Thu, Jun 15, 2017 at 12:11 AM, wrote: > Thank you Mike, the composite joins look like something close to what I > need. However, it seems that they

Re: [sqlalchemy] Purpose of assertion in table reflection test (1.1.9)

2017-05-19 Thread Simon King
On Thu, May 18, 2017 at 11:56 PM, jan.karstens via sqlalchemy < sqlalchemy@googlegroups.com> wrote: > Upgrading a specific dialect (EXASOL) to 1.1.9 made me stumble across this > test (part of test_reflection.py): > > https://github.com/zzzeek/sqlalchemy/blob/rel_1_1_9/lib/ >

Re: [sqlalchemy] Composite column with null property

2017-05-12 Thread Simon King
On Thu, May 11, 2017 at 6:18 PM, wrote: > Hello, > > I have a Money composite column, comprised of an `amount` (Decimal) and a > `currency` (String). Sometimes the amount needs to be NULL, but then I get > an instance of Money(None, 'GBP'). Is there any way to force the

<    1   2   3   4   5   6   7   >