Re: [sqlalchemy] Slow entities pickling for caching purposes

2019-10-10 Thread Mike Bayer
On Thu, Oct 10, 2019, at 2:48 AM, Александр Егоров wrote: > Hello! > > I want to cache query results in a distributed cache (Redis), so I need to > serialize/deserialize fetched entities very fast. > However, it turned that SQLAlchemy entities are very heavy for pickle to > dump/load. Regular

Re: [sqlalchemy] Re: ORM-level “delete” cascade vs. FOREIGN KEY level “ON DELETE” cascade explanation

2019-10-10 Thread Mike Bayer
On Thu, Oct 10, 2019, at 3:53 AM, 'Marc Vegetti' via sqlalchemy wrote: > Hello, first of all, thnak you for your fast answer. > > I was refering to : >> A database level `ON DELETE` cascade is configured effectively on the >> *many-to-one* side of the relationship; that is, we configure it

Re: [sqlalchemy] server_default=text('1970-01-01 00:00:01') changed when run in a different timezone

2019-10-09 Thread Mike Bayer
you probabbly should report this over at https://github.com/agronholm/sqlacodegen On Wed, Oct 9, 2019, at 1:32 PM, Thomas Ryan wrote: > I have the following fields defined in a table. > > `updated` datetime NOT NULL DEFAULT '1970-01-01 00:00:01', > `deleted` datetime NOT NULL DEFAULT

Re: [sqlalchemy] ORM-level “delete” cascade vs. FOREIGN KEY level “ON DELETE” cascade explanation

2019-10-09 Thread Mike Bayer
On Wed, Oct 9, 2019, at 5:14 AM, 'Marc Vegetti' via sqlalchemy wrote: > Hello, > > I'm currently auditing a database which uses sqlalchemy 1.1.9 and PostgreSQL > 10 with Python 3.5. > > There are a few foreign keys which are set to *ON DELETE CASCADE* on the > database but are not set as

Re: [sqlalchemy] How to resolve unique constraint matching errors in case of multiple foreign keys as composite primary keys

2019-10-05 Thread Mike Bayer
if GTDataSetVersion -> GTDataSetImages is one to many, then GTDataSetImages needs to have a foreign key to the primary key of GTDataSetVersion. GTDataSetVersion.gtdatasetid is only part of its primary key and is not unique. you need a composite foriegn key to GTDataSetVersion(version,

Re: [sqlalchemy] Creating Namespaced/Gapless Sequences Using Event Listeners

2019-10-04 Thread Mike Bayer
On Fri, Oct 4, 2019, at 3:57 PM, Scott Colby wrote: > Hello, > > I am attempting to implement a "gapless" sequence using SQLAlchemy's > event listeners instead of DB-level triggers inspired by > [this](https://stackoverflow.com/questions/9984196/postgresql-gapless-sequences) > and similar

Re: [sqlalchemy] boud parameter to NCHAR column in Oracle

2019-10-03 Thread Mike Bayer
(use text().columns()) which SQLAlchemy uses in order to set up cursor.outputtypehandler. Both of these are cx_Oracle things that are unfortunately unique to this DBAPI and they are hugely important; even the django ORM has to use outputtypehandler. On Thu, Oct 3, 2019, at 12:20 PM, Mike Bayer

Re: [sqlalchemy] boud parameter to NCHAR column in Oracle

2019-10-03 Thread Mike Bayer
hey there - you should apply typing behavior which should be safe to apply to any CHAR like this: class PaddedChar(TypeDecorator): impl = NCHAR def process_bind_param(self, value, dialect): if value is not None: value = value + (" " * (self.impl.length - len(value))) return value

Re: [sqlalchemy] Numeric type without scale? Oracle

2019-10-01 Thread Mike Bayer
Hi there - you can use sqlalchemy.dialects.oracle.NUMBER directly: from sqlalchemy import Column from sqlalchemy import MetaData from sqlalchemy import Table from sqlalchemy.dialects import oracle from sqlalchemy.dialects.oracle import NUMBER from sqlalchemy.schema import CreateTable t =

Re: [sqlalchemy] Association table through two columns?

2019-10-01 Thread Mike Bayer
On Mon, Sep 30, 2019, at 12:25 AM, Mateja Putic wrote: > I would like to create an association between a Dataset object and all > Category objects through an intermediate Annotation table. > A Dataset contains a collection of Annotations. Each Annotation has a single > Category. I want

Re: [sqlalchemy] change an existing relationship

2019-09-27 Thread Mike Bayer
On Fri, Sep 27, 2019, at 9:59 AM, Mike Bayer wrote: > > > On Fri, Sep 27, 2019, at 9:34 AM, Julien Cigar wrote: >> On Fri, Sep 27, 2019 at 09:03:53AM -0400, Mike Bayer wrote: >> > >> > >> > On Fri, Sep 27, 2019, at 6:26 AM, Julien Cigar wrote: >&

Re: [sqlalchemy] change an existing relationship

2019-09-27 Thread Mike Bayer
On Fri, Sep 27, 2019, at 9:34 AM, Julien Cigar wrote: > On Fri, Sep 27, 2019 at 09:03:53AM -0400, Mike Bayer wrote: > > > > > > On Fri, Sep 27, 2019, at 6:26 AM, Julien Cigar wrote: > > > On Thu, Sep 26, 2019 at 11:39:52AM -0400, Mike Bayer wrote: > > >

Re: [sqlalchemy] change an existing relationship

2019-09-27 Thread Mike Bayer
On Fri, Sep 27, 2019, at 6:26 AM, Julien Cigar wrote: > On Thu, Sep 26, 2019 at 11:39:52AM -0400, Mike Bayer wrote: > > that's not supported, I would suggest trying to solve your problem in a > > different way. > > > > Ok, that's what I thought.. thanks! > &

Re: [sqlalchemy] join multiple tables using sql alchemy

2019-09-26 Thread Mike Bayer
On Thu, Sep 26, 2019, at 12:53 PM, Nitin Jain wrote: > Hi all > > I want to join multiple tables using sqlalchemy ORM package and really > finding it very difficult. > > Using raw SQL query i am able to do successful query but not using sql > alchemy . > > Please let me know if somebody can

Re: [sqlalchemy] change an existing relationship

2019-09-26 Thread Mike Bayer
that's not supported, I would suggest trying to solve your problem in a different way. On Thu, Sep 26, 2019, at 11:25 AM, Julien Cigar wrote: > Hello, > > I'd like to change a lazy property of an existing relationship (from > 'joined' to 'noload'). I tried the following: > > mapper =

Re: [sqlalchemy] Is it possible to use relationship(lazy='raise') after session.refresh?

2019-09-25 Thread Mike Bayer
that also will apply the lazyload() option to the Group object permanently unless populate_existing() is used on it again. On Wed, Sep 25, 2019, at 3:57 PM, Mike Bayer wrote: > what you are seeing is somewhat backwards due to what might be a bug. in the > example you have, *both* calls to gro

Re: [sqlalchemy] Is it possible to use relationship(lazy='raise') after session.refresh?

2019-09-25 Thread Mike Bayer
what you are seeing is somewhat backwards due to what might be a bug. in the example you have, *both* calls to group.users should be raising, because this object is already present in the identity map so your lazyload() option should not affect this already-present Group object. if you load

Re: [sqlalchemy] misc questions about finding `association_proxy` "columns"

2019-09-24 Thread Mike Bayer
the association proxies are in mapper.all_orm_descriptors if you can look in there as far as "loaded" you have to dig into the proxy and the attribute it is proxying (which if you've done things this way can be a chain of proxies), I'd have to read the source to know the exact API to use :)

Re: [sqlalchemy] Abstracting common hybrid properties

2019-09-23 Thread Mike Bayer
easy enough to create a function def dict_getter(attr, key): @hybrid_property def get(self): return getattr(self, attr).get(key) @get.expression def get(self): return getattr(self, attr)[key] return get class User(Base): phone_number_2= dict_getter("details", "phone_num_2") probably

Re: [sqlalchemy] Help to use no auto rehashing in sqlchemy.

2019-09-23 Thread Mike Bayer
On Mon, Sep 23, 2019, at 2:11 PM, ashish vicky wrote: > Hello All, > Can someone help me use no auto rehashing (as what is used in mysql using > option -A) using create _engine in sqlalchemy.I want to reduce time in > connecting with mysql using sqlalchemy to optimese performance of our >

Re: [sqlalchemy] Marshmallow speed and lazy/eager loading

2019-09-21 Thread Mike Bayer
On Sat, Sep 21, 2019, at 6:15 AM, YKdvd wrote: > I'm using the "marshmallow" serialization library to dump out SQLAlchemy > objects, and I'm trying to track down some slowness issues. The objects have > various relationships (using marshmallow's Nested fields in the mm schema), > and some of

Re: [sqlalchemy] Column name collision with method name

2019-09-13 Thread Mike Bayer
On Fri, Sep 13, 2019, at 10:46 AM, Gary L wrote: > I have a declarative model as below > > > class User(Base): > __tablename__ = 'users' > __table_args__ = { > 'schema':'internal', > 'extend_existing': True, > 'mustexist': True > } > > > The table has a column named

Re: [sqlalchemy] SqlAlchemy vulnerabilities CVE-2019-7164

2019-09-13 Thread Mike Bayer
yes. per the headline linked in that article: "SQLAlchemy through 1.2.17 and 1.3.x **through 1.3.0b2** allows SQL Injection via the order_by parameter." Version 1.3.8 is much newer than version 1.3.0b2. The changelog for the issue is noted in 1.3.0b3 at

Re: [sqlalchemy] Complex Constraints in Many to Many relationships

2019-09-05 Thread Mike Bayer
I wasn't totally sure if it worked! glad i could help On Thu, Sep 5, 2019, at 12:26 PM, Michael P. McDonnell wrote: > You make it seem so easy. > > Thank you! > > On Thu, Sep 5, 2019 at 11:11 AM Mike Bayer wrote: >> __ >> >> >> On Wed, Sep 4, 2019,

Re: [sqlalchemy] Complex Constraints in Many to Many relationships

2019-09-05 Thread Mike Bayer
On Wed, Sep 4, 2019, at 5:12 PM, Michael P. McDonnell wrote: > Hey - > I'm again at a loss of what to google, and as this will ultimately need to be > represented in some fashion in sqlalchemy, I figured this is a great place to > start: > > I have a |person| table and a |team| table with a

Re: [sqlalchemy] Track a "column FOO does not exist" bug.

2019-09-05 Thread Mike Bayer
On Thu, Sep 5, 2019, at 7:50 AM, Riccardo Cagnasso wrote: > I have a table Activity that had a strategic_project_name column. > I removed the strategic_project_name column from the declarative definition > of the Activity table and then the strategic_project_name column from the > database

Re: [sqlalchemy] How to best integrate executing against a pandas dataframe in a custom dialect.

2019-08-30 Thread Mike Bayer
On Thu, Aug 29, 2019, at 10:27 PM, Varun Madiath wrote: > Hi Mike. > > Thank you for taking the time to respond. Responses inline > > On Thu, Aug 29, 2019 at 10:35 AM Mike Bayer wrote: >> __ >> >> hi there, responses inline >> >> On Wed, A

Re: [sqlalchemy] How to best integrate executing against a pandas dataframe in a custom dialect.

2019-08-29 Thread Mike Bayer
hi there, responses inline On Wed, Aug 28, 2019, at 11:39 PM, Varun Madiath wrote: > Hi. > > I'm working to extend the Turbodbc > dialect of the sqlalchemy_exasol > project to support > executing

Re: Paritioned Table Migration

2019-08-29 Thread Mike Bayer
On Thu, Aug 29, 2019, at 8:55 AM, Stephan Gerhard wrote: > Hi, > > I am wondering whether it is possible to use Alembic to define a migration > where I add a partitioned table - a feature that is supported in Postgres 12 > - e.g. using range partitions. >

Re: [sqlalchemy] Raise on attempt to load deferred columns and column properties

2019-08-28 Thread Mike Bayer
On Wed, Aug 28, 2019, at 12:18 PM, Jimmy Jia wrote: > I might just be missing something from the docs here, but is there a way to > raise on attempts to load deferred columns or column properties? > > I'm looking to get behavior equivalent to that of raiseload, to prevent > unintentional N+1

Re: How to rename column on MySQL without deleting existing data?

2019-08-27 Thread Mike Bayer
On Tue, Aug 27, 2019, at 6:15 AM, Mike wrote: > *Setup:* > mysql> SELECT version(); > > * 5.7.27-0ubuntu0.18.04.1 > * Python 3.6.8 > * SQLAlchemy 1.3.6 > * Alembic 1.0.11 > > > *models.py:* > class Experiments(db.Model): > id = db.Column(db.Integer, primary_key=True) > # country =

Re: [sqlalchemy] Pickle of result from query with explicit sqlalchemy.orm.Load() option

2019-08-26 Thread Mike Bayer
I figured out that this is fixable so will be in the next release. On Mon, Aug 26, 2019, at 11:17 AM, Jan Wegger wrote: > Ok, thanks for the reply. My original case was a situation where it seemed > hard to get it right without using Load() directly, but I think I've been > able to work around

Re: [sqlalchemy] Pickle of result from query with explicit sqlalchemy.orm.Load() option

2019-08-26 Thread Mike Bayer
it's unclear if there is an existing issue for this but apparently the Load() object is not pickleable directly due to the objects present in the context, so I would advise to not make use of the Load() object directly. https://github.com/sqlalchemy/sqlalchemy/issues/4823 On Mon, Aug 26,

Re: [sqlalchemy] Re: Advice on cascading polymorphic inheritance

2019-08-22 Thread Mike Bayer
g > there with its name, for instance, Event will put 'event', travel will put > 'travel' and so on? yup > > > On Thursday, August 22, 2019 at 5:00:15 PM UTC+2, Mike Bayer wrote: >> That particular idea is a convenience but is never necessary to get a >> multip

Re: [sqlalchemy] Re: Advice on cascading polymorphic inheritance

2019-08-22 Thread Mike Bayer
That particular idea is a convenience but is never necessary to get a multiple-level inheritance model to work. You simply have the polymorphic_on in the base-most table be the place where the discriminator is stored, and each descendant class defines its discriminator value fully. On Thu,

Re: [sqlalchemy] Explicit Column Combination vs Implicit?

2019-08-21 Thread Mike Bayer
On Wed, Aug 21, 2019, at 1:46 PM, Michael P. McDonnell wrote: > Hey team - > > I've went through the docs, and likely because I'm a bit of a hack - I'm > finding it hard to find my answers (because I'm not sure what I'm > specifically looking to "do" other than "make it work") > > So I have

Re: Alembic: Varying database names per environment?

2019-08-19 Thread Mike Bayer
On Mon, Aug 19, 2019, at 7:24 AM, Scott wrote: > On Monday, August 19, 2019 at 9:58:19 AM UTC+10, Mike Bayer wrote: >> >> >> On Sun, Aug 18, 2019, at 6:50 PM, Scott wrote: >>> Looking to use Alembic to manage migrations. >>> >>> We currently h

Re: Alembic: Varying database names per environment?

2019-08-18 Thread Mike Bayer
On Sun, Aug 18, 2019, at 6:50 PM, Scott wrote: > Looking to use Alembic to manage migrations. > > We currently have different database names in each environment, so for dev, > test and prod we have db_dev, db_test and db_prod respectively. > > Is this database naming scheme going to be

Re: [sqlalchemy] Regarding Data type consideration

2019-08-18 Thread Mike Bayer
I've reached out on Twitter to see if I can attract more Pandas users to this list as this is a pandas-specific issue for which I don't have the expertise to answer. On Sun, Aug 18, 2019, at 5:24 AM, Mohan Raj wrote: > Hi, > > I used "sqlalchemy" in my python code for inserting a Dataframe

Re: [sqlalchemy] StaleDataError when accessing a relationship attribute

2019-08-16 Thread Mike Bayer
On Fri, Aug 16, 2019, at 2:18 PM, Vinit Shah wrote: > I have code that looks like the following: > > games = session.query(Game) > game = [g for g in games][0] > court = game.court # StaleDataError > game. > session.add(game) > > Game looks like: > > class Game(Base): > __tablename__ =

Re: [sqlalchemy] Resource closed error when trying to insert the record in table randomly

2019-08-15 Thread Mike Bayer
On Thu, Aug 15, 2019, at 1:09 PM, Abhishek Sharma wrote: > Thanks Mike for your response. > > It's more likely due to multi threading because this error is coming very > randomly, If this was due to permutations you mentioned then it should happen > every time which is not the case here. > >

Re: [sqlalchemy] Resource closed error when trying to insert the record in table randomly

2019-08-15 Thread Mike Bayer
On Thu, Aug 15, 2019, at 12:25 PM, Abhishek Sharma wrote: > Thanks Mike for your reply. > > We are using cx Oracle as driver OK actually this error is very specific to the ORM session, it's from trying to a work witha transaction that's already done. It can be reproduced in many ways, such

Re: [sqlalchemy] Resource closed error when trying to insert the record in table randomly

2019-08-15 Thread Mike Bayer
On Thu, Aug 15, 2019, at 10:28 AM, Abhishek Sharma wrote: > One of my project is built around Django rest framework and Sqlalchemy as ORM. > > This application is thread based so randomly we are seeing one of thread > transaction showing connection closed error. > > Randomly when my

Re: [sqlalchemy] Missing "SKIP_LOCKED" from inner subquery of CTE

2019-08-12 Thread Mike Bayer
On Mon, Aug 12, 2019, at 9:23 PM, Joel Gibson wrote: > Hi all, > > I've got a queue in postgres that currently uses a raw sql query to dequeue > items. The queue has multiple "topics" that the metadata/selector uses to > dequeue specific items > > DELETE FROM queue > WHERE id = ( > SELECT id

Re: [sqlalchemy] Can't filter on Join?

2019-08-12 Thread Mike Bayer
On Mon, Aug 12, 2019, at 5:49 PM, Michael P. McDonnell wrote: > Hey team - > > I'm trying to figure out how to basically rewrite this: > SELECT > count(task.id) > FROM task > JOIN round on task.game_id = round.game_id > JOIN tournament ON round.tournament_id = tournament.id > WHERE

Re: [sqlalchemy] Postgres array containment query generates FROM-clause that causes failure

2019-08-12 Thread Mike Bayer
ral array (looking at the superclass) >> for now, so my suggested extension might be a bit easier said than >> implemented. >> >> On Thu, Aug 8, 2019 at 7:05 PM Mike Bayer wrote: >>> __ >>> >>> >>> On Thu, Aug 8, 2019, at 11:56 AM, Elmer

Re: [sqlalchemy] Postgres array containment query generates FROM-clause that causes failure

2019-08-08 Thread Mike Bayer
ow, but aren't tested or supported or part of an overall strategy, then we are creating poor assumptions. So I'd prefer we build out real patterns and have them tested before we document them. > > On Thu, Aug 8, 2019 at 5:17 PM Mike Bayer wrote: >> __ >> >> >> On

Re: [sqlalchemy] Postgres array containment query generates FROM-clause that causes failure

2019-08-08 Thread Mike Bayer
On Thu, Aug 8, 2019, at 9:48 AM, Elmer de Looff wrote: > Hi, > > I'm trying to create a query to check whether a small number of given keys > are all present within a selection of a table. Postgres provides array > types/functions for this to check sub/superset properties, which seem to do >

Re: [sqlalchemy] Percentile calculation

2019-08-05 Thread Mike Bayer
note also pysqlite allows Python functions to embedded in SQL directly, which can do the percentile_cont() part but not the WITHIN GROUP part. https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.create_aggregate On Mon, Aug 5, 2019, at 6:30 PM, Jonathan Vanasco wrote: > > > On

Re: [sqlalchemy] Percentile calculation

2019-08-05 Thread Mike Bayer
oblem in Python. > > Is there an easy way to obtain a list of objects generated by multiple > group_by conditions? Then I could calculate the percentiles e.g. in numpy. group_by() accepts any number of expressions and you can use it multiple times. > > Am Montag, 5. August 2019 18:16:38 UTC

Re: [sqlalchemy] Removing a column from a sqlalchemy table

2019-08-05 Thread Mike Bayer
has > the hive dialect for sqlalchemy. > > On Mon, Aug 5, 2019, 19:17 Mike Bayer wrote: >> __ >> >> >> On Sun, Aug 4, 2019, at 11:32 PM, Abdeali Kothari wrote: >>> Thanks for the quick revert. I saw sqlalchemy-migration and have used >>> alembic a

Re: [sqlalchemy] Percentile calculation

2019-08-05 Thread Mike Bayer
does SQLite support WITHIN GROUP ? Try it out on PostgreSQL, I think this is just not syntax SQLite supports. On Mon, Aug 5, 2019, at 10:38 AM, Michael wrote: > Hi! > > I'm really having a great time with sqlalchemy so far! > > Currently I'm trying to apply a percentile function on a ORM

Re: [sqlalchemy] Removing a column from a sqlalchemy table

2019-08-05 Thread Mike Bayer
s and the point at which I'd use SQLAlchemy with such a system is after the data has been put into it entirely If I weren't using Hive, then I wouldn't do things that way. It's not clear if you're seeking to migrate off of Hive or to build a complementary process. > > > On Mon, Aug 5

Re: [sqlalchemy] Removing a column from a sqlalchemy table

2019-08-04 Thread Mike Bayer
On Sun, Aug 4, 2019, at 1:14 PM, Abdeali Kothari wrote: > I am using the sqlalchemy Table class to load up a data schema I am provided. > > Once loaded into sqlalchemy, I want to use some of the existing extensions > like: > - ERD plots - eralchemy > - Auto finding relationships using

Re: [sqlalchemy] One of my declarative table definition not available in metadata even i attached the table with metadata

2019-08-04 Thread Mike Bayer
OK, that is another problem to avoid, if you have two ORM models in different .py files, you need to make sure both .py files have been imported before you can use the mappings or do things like create_all(). from that description it sounds like your "deal" model wasn't imported. there's not

Re: [sqlalchemy] One of my declarative table definition not available in metadata even i attached the table with metadata

2019-08-03 Thread Mike Bayer
= Column(Integer, primary_key=True) e = create_engine("sqlite://", echo=True) Base.metadata.create_all(e) # <-- will cause the error you are seeing On Sat, Aug 3, 2019, at 11:35 PM, Mike Bayer wrote: > > > On Sat, Aug 3, 2019, at 12:37 PM, Abhishek Sharma wrote: >&

Re: [sqlalchemy] One of my declarative table definition not available in metadata even i attached the table with metadata

2019-08-03 Thread Mike Bayer
On Sat, Aug 3, 2019, at 12:37 PM, Abhishek Sharma wrote: > I am using SQLALCHEMY Version 1.2.17 > > I am using declarative approach to define models, One of my declarative table > definition not available in metadata even i attached the table with metadata > so when other table which is in

Re: [sqlalchemy] Unique Constraint in a Table over columns with multiple many to many relationships fails. How to fix ?

2019-08-03 Thread Mike Bayer
On Fri, Aug 2, 2019, at 2:09 AM, Padam Sethia wrote: > > Hey Guys ! > So as the title says it all , I'm try to do the above , but I'm getting SQL > Syntax error when I'm using db.Index to create a unique index . I've tried > all the solutions but nothing seems to work. > P.S : I'm using

Re: [sqlalchemy] Implementing archive deletion for models with relationships

2019-08-03 Thread Mike Bayer
On Tue, Jul 30, 2019, at 3:42 PM, Kata Char wrote: > Hi, > > I was wondering if I can get some pointers on how to do this. I want to copy > data to an archive table before deleting the data. So let's say I have a > model like below > > class ModelA(...): > id = db.Column(db.Integer,

Re: [sqlalchemy] Thank you for SQLAlchemy

2019-08-03 Thread Mike Bayer
On Sat, Aug 3, 2019, at 11:00 AM, Aaron Krohn wrote: > I just wanted to let you all know that I really appreciate the effort put > into the SQLAlchemy library. Its interfaces are extremely simple and > intuitive, and this has been done by using the full extent of Python language > features.

Re: [sqlalchemy] generate_series?

2019-07-30 Thread Mike Bayer
On Tue, Jul 30, 2019, at 1:46 PM, Massimiliano della Rovere wrote: > Years later... > please can you give me some hints on how to write the Alias subclass and the > function to decorate with @complile? > I'm not expert with SQLAlchemy internals. no idea, can you please type out the SQL you

Re: [sqlalchemy] loss of precision when retrieving DATETIME2 column from MSSQL

2019-07-29 Thread Mike Bayer
t_history :') > print(t_history.select()) > > print('** StringDate TypeDecorator only applied to the first > table in a union_all :') > print(t.select().union_all(t_history.select())) > > print('** StringDate TypeDecorator only applied to the first &g

Re: [sqlalchemy] How to catch exceptions (the best practice)

2019-07-29 Thread Mike Bayer
On Sat, Jul 27, 2019, at 4:53 PM, Nestor Diaz wrote: > Hello everybody. > > I am experimenting with sqlalchemy and pyramid, following the tutorial > steps at: > > https://docs.pylonsproject.org/projects/pyramid/en/latest/quick_tutorial/databases.html > > The example above is a wiki, with a

Re: [sqlalchemy] possible bug on sqlite regarding automatic constraints when using alembic recommended naming conventions

2019-07-25 Thread Mike Bayer
On Mon, Jul 22, 2019, at 10:51 PM, Jonathan Vanasco wrote: > > > On Monday, July 22, 2019 at 9:36:10 PM UTC-4, Mike Bayer wrote: >> >> likely , the "create_constraint" flag should default to False for booleans >> and enums. I think it was a mistake to

Re: [sqlalchemy] Pass timestamp with milliseconds to SQLAlchemy backed by SQLite3

2019-07-25 Thread Mike Bayer
Hi there - We would need some context for this. What does CREATE TABLE look like? What is the datatype in use? What does the logging output say, e.g. illustrate the SQL and result output with create_engine(..., echo='debug'). It looks like you are using some epochal oriented datatype but no

Re: [sqlalchemy] possible bug on sqlite regarding automatic constraints when using alembic recommended naming conventions

2019-07-22 Thread Mike Bayer
On Mon, Jul 22, 2019, at 6:01 PM, Jonathan Vanasco wrote: > Mike- > > I'm not sure if this is a bug or docs incompatibility issue, and I know > metadata may be going away soon... but I'm leaning towards a bug. > > I was setting up a test suite for a Pyramid plugin, and used the Alembic >

Re: [sqlalchemy] Selectinload doesn't exploit FK

2019-07-19 Thread Mike Bayer
the patch for the 1.3 series from https://gerrit.sqlalchemy.org/#/c/sqlalchemy/sqlalchemy/+/1369/ and ensure it works and performs as expected for your use case, though a SQLAlchemy release is now overdue and this may go out quickly. > > Le vendredi 19 juillet 2019 01:24:

Re: [sqlalchemy] Selectinload doesn't exploit FK

2019-07-18 Thread Mike Bayer
On Thu, Jul 18, 2019, at 5:02 PM, yoch melka wrote: > Hi, > > According to the documentation > , > from 1.3 "selectin loading can omit the JOIN for a simple one-to-many > collection" in case if the PK is

Re: [sqlalchemy] loss of precision when retrieving DATETIME2 column from MSSQL

2019-07-18 Thread Mike Bayer
reflect event" if isinstance(column_info['type'], DATETIME2): column_info['type'] = StringDatetime event.listen( Table, 'column_reflect', listen_for_reflect) > > br > Peter > > > On Thursday, 18 July 2019 18:30:44 UTC+3, Mike Bayer wrote: >>

Re: [sqlalchemy] loss of precision when retrieving DATETIME2 column from MSSQL

2019-07-18 Thread Mike Bayer
On Thu, Jul 18, 2019, at 7:56 AM, peter bell wrote: > You are correct - it seems the issue is in pyodbc but the pyodbc issue was fixed over a year ago. It seems that you would like to retrieve this value as a string so that you can have precision that's not supported by Python datetime, so

Re: [sqlalchemy] Create ad hoc custom function

2019-07-15 Thread Mike Bayer
ANSFORM) data and then move/copy (LOAD) final table > view to real database. yeah that is a great idea. > > Regards, > Lubos > > On Mon, 15 Jul 2019 at 16:42, Mike Bayer wrote: >> __ >> >> >> On Mon, Jul 15, 2019, at 10:14 AM, Ľuboš Katrinec

Re: [sqlalchemy] Create ad hoc custom function

2019-07-15 Thread Mike Bayer
On Mon, Jul 15, 2019, at 10:14 AM, Ľuboš Katrinec wrote: > I am looking for creating custom Python callable function that would be use > in raw SQL queries, very same to Connection.create_function() > which is > perfectly

Re: [sqlalchemy] SqlAlchemy using a REST engine

2019-07-15 Thread Mike Bayer
I dont have any special insight on this. It would obviously perform pretty poorly, but overall the API you'd want to target first is pep 249: https://www.python.org/dev/peps/pep-0249/ that does all the REST stuff, then SQLAlchemy dialect is documented at

Re: [sqlalchemy] Wrapper Table needs Joins on SELECT, not on Insert.

2019-07-13 Thread Mike Bayer
ptors, e.g. from sqlalchemy import inspect d = { k getattr(some_object, k) for k in inspect(some_object).mapper.all_orm_descriptors } https://docs.sqlalchemy.org/en/13/orm/mapping_api.html?highlight=all_orm_descriptors#sqlalchemy.orm.mapper.Mapper.all_orm_descriptors > > On Fri,

Re: [sqlalchemy] Wrapper Table needs Joins on SELECT, not on Insert.

2019-07-12 Thread Mike Bayer
On Fri, Jul 12, 2019, at 11:20 AM, Michael P. McDonnell wrote: > Hey Team - > > So I'm working on a relatively fun hierarchy that allows me to relate tasks > to games. > So I have 2 tables: > > # A Generic Task Definition - not related to anything > class Task_Definition(Base): > def

Re: [sqlalchemy] Using sqlalchemy to figure out multi table relationships

2019-07-11 Thread Mike Bayer
On Thu, Jul 11, 2019, at 7:41 AM, Abdeali Kothari wrote: > I am trying to use SQLAlchemy to do some smart joins for me without me having > to explicitly figure out the joins during queries. > (i.e. by figuring out the relationships on its own to figure out how the > tables are related to each

Re: [sqlalchemy] Using sqlalchemy to figure out multi table relationships

2019-07-11 Thread Mike Bayer
On Thu, Jul 11, 2019, at 7:41 AM, Abdeali Kothari wrote: > I am trying to use SQLAlchemy to do some smart joins for me without me having > to explicitly figure out the joins during queries. > (i.e. by figuring out the relationships on its own to figure out how the > tables are related to each

Re: [sqlalchemy] with_entities referring to SQlite column aliased with

2019-07-11 Thread Mike Bayer
On Thu, Jul 11, 2019, at 2:57 AM, Dieter Menne wrote: > > `I have posted this on Stackoverflow, but there was no response. > > https://stackoverflow.com/questions/56891733/with-entities-referring-to-sqlite-column-aliased-with-label-self-contained-re > > How do I use .with_entities to refer to

Re: [sqlalchemy] Using metadata built from parent process's engine

2019-07-10 Thread Mike Bayer
On Wed, Jul 10, 2019, at 5:04 PM, Zach wrote: > Our application uses gunicorn and we are looking to enable `preload_app`. In > preparation, we moved the creation of the sqlalchemy engine into a post-fork > hook for each gunicorn worker, ensuring that DB connections are created > separately

Re: [sqlalchemy] load extension spatialite in windows

2019-07-10 Thread Mike Bayer
t; Sorry for my ignorance but I don't understand what you tell me to do with > cPython. Subscribe to this mailing list: https://mail.python.org/mailman/listinfo/python-list then ask them there about this error you get when you use sqlite3 directly. > > Le mercredi 10

Re: [sqlalchemy] load extension spatialite in windows

2019-07-10 Thread Mike Bayer
I have no information on that, this has to do with the sqlite3 module included with Python: import sqlite3 conn = sqlite3.connect(":memory:") conn.load_extension("c:\\path\\to\\dll") Use cPython resources to get help and use the above code as what you're trying to get to work:

Re: [sqlalchemy] Finding original "type" when using as_mutable()

2019-07-10 Thread Mike Bayer
On Wed, Jul 10, 2019, at 3:20 AM, Lele Gaifax wrote: > Hi, > > I would like to find an automated way to collect all columns of any mapped > class which type is declared as > > ColType.as_mutable(ConcreteType) > > In an application I'm developing I use sqlalchemy-media to handle multi-media >

Re: [sqlalchemy] MetaData().reflect() fails on engine with non-default isolation level

2019-07-08 Thread Mike Bayer
On Mon, Jul 8, 2019, at 6:08 AM, Gunnar Þór Magnússon wrote: > Hello, > > Some legacy code at work that I don't fully understand (and whose authors are > all long gone) does the following to eventually insert some values into the > table it gets: > > meta =

Re: [sqlalchemy] programming error (psycopg2.ProgrammingError) can't adapt type 'Point'

2019-07-08 Thread Mike Bayer
On Mon, Jul 8, 2019, at 4:45 AM, Mauro Mussin wrote: > I have a postgres-postgis dB with a geometry:point field: if I insert the > values directly > INSERT INTO points(coordinates) VALUES (ST_GeomFromText('POINT(10.809003 > 54.097834)',4326)); > > no issue, but if I use this sequence

Re: [sqlalchemy] Re: not the same number of columns in the 2 queries of the recursive request

2019-07-08 Thread Mike Bayer
are you able to set echo="debug" on your create_engine(), view the SQL being emitted as well as the results being returned, and then ensure the SQL statement and results are what you are looking for? once you have that we can make sure the ORM interprets these results correctly. On Sun, Jul

Re: [sqlalchemy] not the same number of columns in the 2 queries of the recursive request

2019-07-07 Thread Mike Bayer
On Sun, Jul 7, 2019, at 9:29 AM, Olivier SAINT-EVE wrote: > I created this recursive query: > `element0 = aliased(Territoire) sub_territories = session.query(element0, element0.id). \ filter(element0.id == 1). \ filter(element0.scale != 'Region'). \

Re: [sqlalchemy] Pyodbc programming error while using Sybase

2019-07-05 Thread Mike Bayer
t this database cannot be supported at this time. > > I was able to print out the column names in the tables using "users.columns". > > I tried omitting the dbo "schema" but then I get a "NoSuchTableError", so I > guess I need that. > > I appreciate y

Re: [sqlalchemy] Pyodbc programming error while using Sybase

2019-07-05 Thread Mike Bayer
Unfortunately the Sybase dialect is not supported right now, but also I don't see anything obviously wrong with the query you have, except perhaps Sybase doesn't like that you have a table named "Users" that is using quoting; it is possible that it wants a different quoting character, not sure.

Re: [sqlalchemy] "No such polymorphic_identity" when models in different modules

2019-07-05 Thread Mike Bayer
On Fri, Jul 5, 2019, at 6:16 AM, Simon King wrote: > In Python, modules are executed when they are imported. Class > definitions are executable statements, where the metaclass is called > to construct the *class*. When you import a module containing > declarative classes, the SQLAlchemy

Re: [sqlalchemy] "No such polymorphic_identity" when models in different modules

2019-07-05 Thread Mike Bayer
On Fri, Jul 5, 2019, at 6:16 AM, Simon King wrote: > In Python, modules are executed when they are imported. Class > definitions are executable statements, where the metaclass is called > to construct the *class*. When you import a module containing > declarative classes, the SQLAlchemy metaclass

Re: [sqlalchemy] "No such polymorphic_identity" when models in different modules

2019-07-04 Thread Mike Bayer
On Thu, Jul 4, 2019, at 8:14 AM, natsjoo sodillepa wrote: > @Simon. > Interesting point. I create the DB and the instances in one script. The data > in the db seems to be correct. > However the error occurs in a second script which almost is like this: > > import ClassA2 > > ... create

Re: [sqlalchemy] How to update jsonb blob subset values using sqlalchemy orm ?

2019-07-04 Thread Mike Bayer
it looks like Postgresql 9.5+ has a new function jsonb_set that does this, this can be used with func. If you aren't on pg9.5 you might have to update the whole value. full POC below from sqlalchemy import Column from sqlalchemy import create_engine from sqlalchemy import func from sqlalchemy

Re: [sqlalchemy] Grouping related Columns in table definitions and Python object reconstruction

2019-07-03 Thread Mike Bayer
On Wed, Jul 3, 2019, at 4:47 AM, Simon King wrote: > On Wed, Jul 3, 2019 at 3:46 AM gamcil wrote: > > > > > > Awesome thanks for the extensive reply. > > > > This is the first time I've played with descriptor classes, so I'm sorry if > > this is really basic stuff. > > > > I set up my view

Re: [sqlalchemy] from_statement and cte problem

2019-07-01 Thread Mike Bayer
_alias).join(parents, locality_alias.id == > parents.c.parent_id) > ) > > cte = aliased(Locality, q) > > return session.query(cte).order_by(cte.id) > > return get_locality_path_q(self.id) > > вторник, 2 июля 2019 г., 0:03:20 UTC+3 пользователь Mike Bayer написал: >>

Re: [sqlalchemy] from_statement and cte problem

2019-07-01 Thread Mike Bayer
30 июня 2019 г., 20:26:42 UTC+3 пользователь Mike Bayer написал: >> >> >> On Sun, Jun 30, 2019, at 5:37 AM, sector119 wrote: >>> Nice, thanks a lot, Mike, now it works as expected >> >> that's great. the docs are not good here, there's not enough discussion

Re: [sqlalchemy] Grouping related Columns in table definitions and Python object reconstruction

2019-07-01 Thread Mike Bayer
On Mon, Jul 1, 2019, at 5:56 AM, gamcil wrote: > Hi, > > I'm new to SQLAlchemy/ORMs - previously I had just been interacting directly > with the builtin SQLite driver and had built up my own mess of a mapping > system. > > 1) I'm starting to convert some classes in a Python package to

Re: [sqlalchemy] from_statement and cte problem

2019-06-30 Thread Mike Bayer
cte = aliased(Locality, q) > > *return *session.query(cte).order_by(cte.id) > > *return *get_locality_path_q(self.id) > > воскресенье, 30 июня 2019 г., 1:11:21 UTC+3 пользователь Mike Bayer написал: >> >> >> On Sat, Jun 29, 2019, at 11:24

Re: [sqlalchemy] from_statement and cte problem

2019-06-29 Thread Mike Bayer
On Sat, Jun 29, 2019, at 11:24 AM, sector119 wrote: > Hello, > > I have Locality model with 'path' property to get path from 'root' of tree to > current item, everything works ok, but > I can't get result as Locality instance list.. > When I use >

Re: Python 3.7 - RuntimeError: generator raised StopIteration

2019-06-28 Thread Mike Bayer
On Fri, Jun 28, 2019, at 4:01 PM, gbr wrote: > I've upgraded my application to Python 3.7 and to the latest version of > Alembic which triggers an exception when `context.get_current_revision()` is > called. > > ``` > File "app.py", line 395, in check_database_version > current_rev =

Re: [sqlalchemy] 'selectin' loading with composite keys on DB2 for i

2019-06-27 Thread Mike Bayer
On Thu, Jun 27, 2019, at 2:11 PM, Steven James wrote: > Currently, `selectin` loading with composite keys works for me on MySQL and > SQLite. The documentation states that it also works with Postgres. I'm > currently trying to get it working on DB2 (connecting to a DB2 for i, 7.2 > system. >

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