Re: [sqlalchemy] sequence in sqlalchemy

2020-07-03 Thread Mike Bayer
hi there - SQLite does not support SEQUENCE objects. On Fri, Jul 3, 2020, at 1:14 AM, Anoop Thiparala wrote: > id = db.Column(db.Integer, Sequence('patients_seq', start=1, > increment=1) , primary_key=True) > > any reason why this is not working with sqlite3 > > -- > SQLAlchemy -

Re: [sqlalchemy] "Virtual models" for JSONB data?

2020-07-03 Thread Mike Bayer
On Fri, Jul 3, 2020, at 9:21 AM, Pedro Ferreira wrote: > Hi, > > I was wondering if there's some way to create some sort of a "virtual" > model which is not based on an actual table? > > Use case: I have a model (e.g. `Room`) which contains a `data` JSONB > attribute/column which is supposed to

Re: [sqlalchemy] Hoarded RAM

2020-07-02 Thread Mike Bayer
On Thu, Jul 2, 2020, at 12:21 PM, Massimiliano della Rovere wrote: > Greetings, > I am using > * SQLAlchemy: 1.3.3 > * psycopg2-binary: 2.8.3 > * postgresql: 9.6 > > While running a SQLAlchemy CORE script that makes lots of updates (about > 300k), some inserts (about 50k) and commits data only

Re: [sqlalchemy] inspection does not update mapper schema when schema assigned to declarative during runtime

2020-07-02 Thread Mike Bayer
On Thu, Jul 2, 2020, at 12:23 PM, Peter Lai wrote: > It appears that if during runtime I assign a schema to declarative, then > `inspect()` it, the resulting Selectable does not have the schema assigned to > it: > > in model.py: > > from sqlalchemy import Column, String, DateTime > from

Re: [sqlalchemy] Getting SQLite INTEGER PRIMARY KEY for a column

2020-07-01 Thread Mike Bayer
On Wed, Jul 1, 2020, at 9:52 PM, Richard Damon wrote: > I am using SQLAlchemy ORM with a SQLite database, and many of my tables > will have a simple integer primary key, with lots of foreign keys > referencing them. It should improve efficiency if that integer primary > key was the alias for the

Re: [sqlalchemy] sqlacodegen error

2020-07-01 Thread Mike Bayer
Sqlalchemy has recently added support for computed column defaults, which are different than regular SQL defaults. The sqlacodegen tool will need to be updated to support this concept. You can request this via their issue tracker, where it seems this is already being discussed at

Re: [sqlalchemy] Locking method used in SQLAlchemy (postgres)

2020-06-29 Thread Mike Bayer
SQLAlchemy doesn't do anything explicit as far as pessimistic locking, this comes down to the isolation level that is set on the current transaction and by default it makes a psycopg2 connection and does not change anything about it. so to get an intro to what happens when you make a psycopg2

Re: [sqlalchemy] MSSQL with PyODBC: StaleDataError on UPDATE statement

2020-06-26 Thread Mike Bayer
engine.base.Engine (True, 6248) > > The result also indicated that 5051 rows where affected, but I don't get it > why... There is clearly only one Measurement with ID 6248... I know that > certain triggers are executed if IsCompleted is changed, so maybe this has an > effect on the repo

Re: [sqlalchemy] Re: MSSQL with PyODBC: StaleDataError on UPDATE statement

2020-06-26 Thread Mike Bayer
yeah that is just disabling the check, the "5000 rows matched" is a critical malfunction referring to non-working primary key. On Fri, Jun 26, 2020, at 10:39 AM, jue...@gmail.com wrote: > Strangely, if I add the following mapper_args, it is working with a warning > (SAWarning: Dialect

Re: [sqlalchemy] MSSQL with PyODBC: StaleDataError on UPDATE statement

2020-06-26 Thread Mike Bayer
hi - does your Measurement table have a primary key constraint present, and does this primary key constraint consist of exactly the "ID" column only and no other columns? it would appear you have not mapped the primary key correctly. On Fri, Jun 26, 2020, at 9:57 AM, jue...@gmail.com wrote:

Re: [sqlalchemy] jsonb_agg with an InstrumentedAttribute

2020-06-25 Thread Mike Bayer
is "question_choice" a table name? use json_agg(literal_column("question_choice")) On Thu, Jun 25, 2020, at 5:38 AM, Julien Cigar wrote: > Hello, > > I'd like to use a sql.func.jsonb_agg() with the following > InstrumentedAttribute: > > orm.mapper( > Question,

Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-19 Thread Mike Bayer
OK great, I was just throwing out assorted debugging techniques to help you find the problem On Fri, Jun 19, 2020, at 12:43 AM, Venkata Siva Naga Tatikonda wrote: > Thanks Mike, able to achieve the desired results. > > > On Thursday, June 18, 2020 at 12:36:15 PM UTC-7, Mike

Re: [sqlalchemy] FetchedValue() updated by UPDATE to a different table

2020-06-18 Thread Mike Bayer
the Session doesnt scan every object on every flush, only those that have been marked as dirty. you should use an event handler such as after_flush() to go through the list of parent objects that have changed, traverse through the child objects you care about and call session.expire() on the

Re: [sqlalchemy] inserting into array column sqlalchmey 1.3.17

2020-06-18 Thread Mike Bayer
On Thu, Jun 18, 2020, at 3:35 PM, Mariana Salgueiro wrote: > Hello! > > I have two Flask projects that connect to postgresql databases and i > encountered an error while trying to insert a value into an array. > > My first project was made back in 2018 and we were using SQLAlchemy 1.1.12 >

Re: [sqlalchemy] alembic (1.4.2) revision --autogenerate hang

2020-06-18 Thread Mike Bayer
this is due to concurrent database connections where one or more of them has acquired a lock on a schema object such as a Table and other DDL operations against that object are blocked. look at your processlist on the database server, or run a query against pg_stat_activity on the database

Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-18 Thread Mike Bayer
what's expected before integrating into the bigger application. On Thu, Jun 18, 2020, at 3:35 PM, Mike Bayer wrote: > > > On Wed, Jun 17, 2020, at 8:59 PM, Venkata Siva Naga Tatikonda wrote: >> Hello Mike, >> >> I've embedded the following code within the

Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-18 Thread Mike Bayer
st want to let you know that, we are using scoped_session with a >>> session_factory object to db connections. Does this approach still suitable >>> for connections using session ? >>> >>> Also, we have custom module where we have separate functions for gener

Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-17 Thread Mike Bayer
t; other application python files to create and close sessions accordingly. This recipe takes place at the level of the Engine so the creation of the Session is not relevant to how it works. > > Thanks, > Pavan. > > On Wednesday, June 17, 2020 at 5:35:59 AM UTC-7, Mike Bayer wrote: &g

Re: [sqlalchemy] Changing database credentials after engine creation

2020-06-17 Thread Mike Bayer
We're going to need an FAQ entry for this since this now comes up regularly for everyone using AWS. There are two methods to manipulate the parameters sent to connect that are independent of the URL. They are both described now at

Re: [sqlalchemy] Connect to multiple Oracle DBs via LDAP

2020-06-16 Thread Mike Bayer
sounds like a cx_Oracle issue ? I don't really understand what this means. A particular Engine can only connect to one database at a time in any case. Contact cx_Oracle devs at https://github.com/oracle/python-cx_Oracle/issues Python doesn't support JDBC unless you're using Jython which

Re: [sqlalchemy] MS-SQL/PyODBC/Linux: How to set a query timeout?

2020-06-15 Thread Mike Bayer
it looks like pyodbc has a timeout attribute on connection: https://code.google.com/archive/p/pyodbc/wikis/Connection.wiki but no init argument for that so youd need to use an event engine = create_engine("mssql+pyodbc:// ...") from sqlalchemy import event @event.listens_for(engine, "connect")

Re: [sqlalchemy] Handling multiple very similar tables

2020-06-05 Thread Mike Bayer
What's important here is how you would use these classes. that is, if you want to have them all laid out explicitly, and your code will do things like " session.query(Table157).all() ", that is, refer to them explicitly, versus these tables are all part of some kind of dynamic data structure,

Re: [sqlalchemy] how do I update a relationship that goes through mulitple tables?

2020-06-03 Thread Mike Bayer
On Wed, Jun 3, 2020, at 3:42 PM, Abbey Reisle wrote: > sqlalchemy version: 1.2.16 > database: mysql 5.7 > > so I currently have a relationship between 2 tables (that has a join table) > that works well for querying, but I need to be able to update as well > > I've tried a few different things

Re: [sqlalchemy] Ocassional Gevent BlockingSwitchOutError crashes when using pool_recycle

2020-06-03 Thread Mike Bayer
Correction, _finalze_fairy() will be doing the rollback() for normal close() as well. anyway you need to make sure those closes are inline with your greenlets and not happening in other greenlets or threads due to GC. On Wed, Jun 3, 2020, at 8:58 AM, Mike Bayer wrote: > Are those err

Re: [sqlalchemy] Ocassional Gevent BlockingSwitchOutError crashes when using pool_recycle

2020-06-03 Thread Mike Bayer
Are those errors appearing in the logs only but not blocking requests? those are cleanouts of pooled connections where the rollback() method must be called. if these pooled connections aren't gracefully closed in your greenlets they will be subject to the garbage collector thread where the

Re: [sqlalchemy] Union query between multiple tables

2020-06-02 Thread Mike Bayer
yes, for example with select(): s1 = select([t.c.c1, t.c.c2, t.c.c3]) s2 = select([t2.c.c1, t.c.c2, null().label('col4'), null.label('col5')]) u1 = union(s1, s2) I'd recommend using union() and select() to create these queries. the ORM Query.union() method is not as easy to use and long term

Re: [sqlalchemy] forcing (composite) primary key order?

2020-06-01 Thread Mike Bayer
yes use the PrimaryKeyConstraint() construct https://docs.sqlalchemy.org/en/13/core/constraints.html?highlight=primarykeyconstraint#sqlalchemy.schema.PrimaryKeyConstraint here you'd want to put it in your __table_args__ and remove primary_key=True from each column On Mon, Jun 1, 2020, at

Re: [sqlalchemy] Using CTE without JOIN

2020-06-01 Thread Mike Bayer
thanks for the easy test. you want your IN to be against "SELECT * FROM cte" so you need to tell it to select() from that CTE: parent_cte = session.query(Parent).cte("parent_cte") query = ( session.query(Child).filter(Child.parent_id.in_(parent_cte.select())).all() ) if you just put the CTE in

Re: [sqlalchemy] Re: Presenting a higher-level view of a physical table to the end-user

2020-05-31 Thread Mike Bayer
This seems straightforward, try reading through the tutorial at https://docs.sqlalchemy.org/en/13/core/tutorial.html which covers the basic idea. SQLAlchemy is designed first and foremost to present SQL statements as composable constructs that work like views, and that is what the select()

Re: [sqlalchemy] Cascade child updates onto the parent

2020-05-28 Thread Mike Bayer
On Wed, May 27, 2020, at 3:57 PM, Colton Allen wrote: > Hello, > > I'm trying to automate a backref update. Basically, when a child model is > inserted or updated I want the parent model's "updated_at" column to mutate. > The value should be the approximate time the user-child-model was

Re: [sqlalchemy] AWS RDS generate-db-auth-token and Redshift get-cluster-credentials

2020-05-22 Thread Mike Bayer
se = client.describe_db_instances(DBInstanceIdentifier=name) > return next(iter(response['DBInstances']), None) > > > # Make sure to actually register it > RdsEngineStrategy() > > # Caller code > engine = > sqlalchemy.create_engine("postgres://user@instanc

Re: [sqlalchemy] AWS RDS generate-db-auth-token and Redshift get-cluster-credentials

2020-05-22 Thread Mike Bayer
You can modify how the engine makes connections using the do_connect event hook: https://docs.sqlalchemy.org/en/13/core/events.html?highlight=do_connect#sqlalchemy.events.DialectEvents.do_connect each time the engine/ pool go to make a new connection, you can affect all the arguments here, or

Re: [sqlalchemy] Pyodbc creator function ignored in create_engine (mssql)

2020-05-22 Thread Mike Bayer
that's only a warning, it's not a failure. We will look into the warning message, however if you e.connect(), it works fine. On Fri, May 22, 2020, at 6:29 AM, Peter Lai wrote: > example: > > import pyodbc > > from sqlalchemy import create_engine > > def creator(): > config = { > 'driver':

Re: [sqlalchemy] Passing reference to model to model column_property function

2020-05-17 Thread Mike Bayer
On Sun, May 17, 2020, at 6:54 AM, Erol Merdanović wrote: > Hi > > First thank you for your reply. > > @Mike, yes. I wish to pass the row products row. I'm attaching working SQL > >> SELECT *, get_product_price(products) FROM products; > > This works great in postgres. I tried it also on

Re: [sqlalchemy] Passing reference to model to model column_property function

2020-05-16 Thread Mike Bayer
On Sat, May 16, 2020, at 1:04 PM, Erol Merdanović wrote: > Hi > > I have a model definition > > class Product(db.Model): > __tablename__ = "products" > > id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) > sku = db.Column(db.String(255), nullable=False, unique=True,

Re: [sqlalchemy] hiding/encrypting the Oracle database connection information?

2020-05-15 Thread Mike Bayer
that issue is unfortunately one of the great mythological stories of business application development, how to configure an application such that the database credentials are not present in a config file where they can be viewed. the scope of that issue is way outside of SQLAlchemy and

Re: [sqlalchemy] test_types.py

2020-05-15 Thread Mike Bayer
test/sql/test_types.py is part of SQLAlchemy's internal testing for the "types" system. The testing/suite/test_types.py suite is part of SQLAlchemy's exported third party dialect test system which is described at https://github.com/sqlalchemy/sqlalchemy/blob/master/README.dialects.rst . if

Re: [sqlalchemy] connection close() questions

2020-05-14 Thread Mike Bayer
nfortunately. it's not supposed to do that now. but it's not as much of an emergency since it is working around the problem. i will try your standalone test case again. > > > On Wed, May 13, 2020 at 1:21 PM Mike Bayer wrote: >> __ >> this is getting released today in any

Re: [sqlalchemy] connection close() questions

2020-05-13 Thread Mike Bayer
: > Very good, will do when I find time. > > Thank you! > > > On Wed, May 13, 2020 at 1:07 PM Mike Bayer wrote: >> __ >> feel free to test the patch at: >> >> https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/1965 >> >> this patch incl

Re: [sqlalchemy] connection close() questions

2020-05-13 Thread Mike Bayer
> > On Wed, May 13, 2020 at 11:54 AM Mike Bayer wrote: >> __ >> nevermind, you've managed to find a case that trips it up for the connection >> pool >> >> release today >> >> >> >> On Wed, May 13, 2020, at 11:51 AM, Mike

Re: [sqlalchemy] connection close() questions

2020-05-13 Thread Mike Bayer
nevermind, you've managed to find a case that trips it up for the connection pool release today On Wed, May 13, 2020, at 11:51 AM, Mike Bayer wrote: > > > On Wed, May 13, 2020, at 11:39 AM, Kent Bower wrote: >> In this script, conn.close() does *not *call rollback on

Re: [sqlalchemy] connection close() questions

2020-05-13 Thread Mike Bayer
ings have changed dramatically. Should not be the case for any released version, please confirm > > On Wed, May 13, 2020 at 11:31 AM Mike Bayer wrote: >> __ >> Haven't looked deeply but so far what you need to know is that conn.close() >> *ALWAYS* rolls back the transact

Re: [sqlalchemy] connection close() questions

2020-05-13 Thread Mike Bayer
Haven't looked deeply but so far what you need to know is that conn.close() *ALWAYS* rolls back the transaction, just not at the Engine level, it's at the connection pool level so you won't see it when logging / event hooking on the Engine. turn on echo_pool and you will see this, in modern

Re: [sqlalchemy] Oracle Sqalchemy connection pooling

2020-05-12 Thread Mike Bayer
you can query for active connections in Oracle with the V$SESSION view: http://www.dba-oracle.com/concepts/query_active_users_v$session.htm https://stackoverflow.com/a/199567/34549 you can get answers like these from googling or stackoverflow On Tue, May 12, 2020, at 3:01 AM, Oğuzhan Kaya

Re: [sqlalchemy] Query time generated columns like hybrid properties(?)

2020-05-09 Thread Mike Bayer
r_id = request.args... > query(Post, func.IF(PostLike.user_id == user_id, PostLike.like_type, > None).label('user_like')) > > And also this as nested for PostCommentLike and PostCOmmentReplyLike. > > I hope It's more clear what I need. > > 8 Mayıs 2020 Cuma 17:27:58 UTC

Re: [sqlalchemy] Query time generated columns like hybrid properties(?)

2020-05-08 Thread Mike Bayer
On Fri, May 8, 2020, at 5:20 AM, taha wrote: > Hi, > > This is simplified version of my post-comment-like models. There's 2 level of > nesting. > > > class Post(Base): > description = db.Column(db.Text()) > comments = relationship("PostComment", backref="post") > post_likes =

Re: [sqlalchemy] Advice for handling QueuePool limit exceptions (3o7r)

2020-05-06 Thread Mike Bayer
On Wed, May 6, 2020, at 11:24 AM, Colton Allen wrote: > Specifically: https://docs.sqlalchemy.org/en/13/errors.html#error-3o7r > > I think I've got a good handle on what the problem is. I just don't have the > experience to know how to solve it effectively and with confidence. > > Just some

Re: [sqlalchemy] sqlalchemy list connections inside connection pool

2020-05-06 Thread Mike Bayer
0, at 8:45 AM, Oğuzhan Kaya wrote: > what is mean that checkedout checkedin connection and why When connection is > closed connection in pool number increases? > > 5 Mayıs 2020 Salı 19:50:22 UTC+3 tarihinde Mike Bayer yazdı: >> engine.pool has some metrics on it: >&

Re: [sqlalchemy] Re: SQLAlchemy: UnicodeEncodeError: 'ascii' codec can't encode characters (db engine encoding ignored?)

2020-05-06 Thread Mike Bayer
:tiger@oracle1120/?encoding=utf-8") >>> e.dialect.create_connect_args(e.url) ([], {'encoding': 'utf-8', 'dsn': 'oracle1120', 'password': 'tiger', 'user': 'scott'}) On Wed, May 6, 2020, at 8:43 AM, Mike Bayer wrote: > I see you are using an "encoding" on cx_Oracle connect(), which SQ

Re: [sqlalchemy] Re: SQLAlchemy: UnicodeEncodeError: 'ascii' codec can't encode characters (db engine encoding ignored?)

2020-05-06 Thread Mike Bayer
I see you are using an "encoding" on cx_Oracle connect(), which SQLAlchemy does not use; this parameter appears to be added to cx_Oracle only recently. The standard way to set Oracle encodings is via the NLS_LANG environment variable, please use this parameter when dealing with Oracle client

Re: [sqlalchemy] Adding extra constraints to monkey-patched model classes

2020-05-06 Thread Mike Bayer
On Wed, May 6, 2020, at 7:19 AM, Alejandro Avilés wrote: > I'm working on a project where I need to add additional columns to tables > defined in a different package. This is done via monkeypatching the model > classes. I need now to also add additional constraints, but I'm getting no > luck

Re: [sqlalchemy] generate top-level python code for an alembic revision from render_item

2020-05-05 Thread Mike Bayer
it's pretty doable if you add a new ${thing} to your mako template. getting a value in there requires a trick, there's an example of it here: https://github.com/sqlalchemy/alembic/issues/686#issuecomment-616828129 which is to put a dictionary inside of another dictionary and pass that as

Re: [sqlalchemy] sqlalchemy list connections inside connection pool

2020-05-05 Thread Mike Bayer
connections you would use the event listeners and track them yourself: https://docs.sqlalchemy.org/en/13/core/events.html#sqlalchemy.events.PoolEvents On Tue, May 5, 2020, at 12:49 PM, Mike Bayer wrote: > engine.pool has some metrics on it: > > >>> from sqlalchemy import creat

Re: [sqlalchemy] sqlalchemy list connections inside connection pool

2020-05-05 Thread Mike Bayer
engine.pool has some metrics on it: >>> from sqlalchemy import create_engine >>> e = create_engine("mysql://scott:tiger@localhost/test") >>> e.pool.status() 'Pool size: 5 Connections in pool: 0 Current Overflow: -5 Current Checked out connections: 0' >>> e.pool.checkedout() 0 >>> c1 =

Re: [sqlalchemy] SQLite supports generated column, but SQLAlchemy doesn't seem to know this

2020-05-01 Thread Mike Bayer
On Fri, May 1, 2020, at 10:55 AM, bb1898 wrote: > Using Python 3.8.2, SQLAlchemy 1.3.16 on Windows 10. > > From version 3.31.0 (2020-01-22) SQLite supports generated columns; > documentation: https://sqlite.org/gencol.html > So I tried to create a table in a SQLite database using this table

Re: [sqlalchemy] Join while filtering on M2M

2020-05-01 Thread Mike Bayer
On Thu, Apr 30, 2020, at 8:17 AM, Marat Sharafutdinov wrote: > from sqlalchemy import Column, ForeignKey, Integer, create_engine > from sqlalchemy.ext.declarative import declarative_base > from sqlalchemy.orm import relationship, sessionmaker > > Base = declarative_base() > > class User(Base):

Re: [sqlalchemy] Transforming the expression of an aliased relationship

2020-04-30 Thread Mike Bayer
only the ORM version of it! I'm glad it's useful because I was not sure if anyone actually uses that function anymore, but there you go. On Thu, Apr 30, 2020, at 10:46 AM, Marnix le Noble wrote: > This is exactly what I was looking for! That's amazing, thank you very much. > I wasn't aware

Re: [sqlalchemy] Transforming the expression of an aliased relationship

2020-04-30 Thread Mike Bayer
If you are able to use the relationship to generate the onclause, at some point you need to know both that you are using that relationship as part of your onclause, and that the target is going to be some target. That's when the decision as to be made and you can do it using the ORM join

Re: [sqlalchemy] Best way to implement PostgreSQL materialized views?

2020-04-29 Thread Mike Bayer
Addition of views to SQLAlchemy is an extremely long term issue that has never been done, largely because we have a recipe that works well enough for most cases, which you have probably seen, at https://github.com/sqlalchemy/sqlalchemy/wiki/Views. The issue itself is

Re: [sqlalchemy] debugging DetachedInstanceError

2020-04-23 Thread Mike Bayer
also the item can be detached if it was deleted in a previous flush On Wed, Apr 22, 2020, at 8:57 PM, Jonathan Vanasco wrote: > I'm trying to figure out how I got a DetatchedInstanceError > > > DetachedInstanceError: Parent instance is > not bound to a Session; lazy load operation of

Re: [sqlalchemy] debugging DetachedInstanceError

2020-04-23 Thread Mike Bayer
Using the event hook is likely the most direct way to see where it's happening, either via logging or pdb: https://docs.sqlalchemy.org/en/13/orm/events.html?highlight=persistent_to_detached#sqlalchemy.orm.events.SessionEvents.persistent_to_detached On Wed, Apr 22, 2020, at 8:57 PM, Jonathan

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-15 Thread Mike Bayer
T_AsGeoJSON(Lake, 'geom')]) > returns a complete GeoJson with properties: > { > "type": "Feature", > "geometry": { > "type": "LineString", > "coordinates": [[0, 0], [1, 1]] > }, > "properties":

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-15 Thread Mike Bayer
* id, gis.lake.geom *AS* geom, %(dummy_val)s >> *AS* dummy_attr >> *FROM* gis.lake) *AS* anon_1] >> [parameters: {'dummy_val': 10, 'ST_AsGeoJSON_2': 'geom'}] > How can I get the alias of an aliased selectable? > > > Le mar. 14 avr. 2020 à 18:33, Mike

Re: [sqlalchemy] Insert statement and DEFAULT keyword

2020-04-14 Thread Mike Bayer
of (yet). > > Of course, I may be missing something, probably obvious, that would explain > why nobody asked about this before. Hope it is a bit clearer. > > Regards, > Nicolas > > Le mardi 14 avril 2020 18:35:48 UTC+2, Mike Bayer a écrit : >> >> >> On Tue

Re: [sqlalchemy] Insert statement and DEFAULT keyword

2020-04-14 Thread Mike Bayer
On Tue, Apr 14, 2020, at 10:41 AM, Nicolas Caniart wrote: > Hi ! > > I've been looking into the documentation but could not find it. > What is the proper way to insert a DEFAULT keywork in the tuples of the > VALUES clause in an INSERT statement ? As in > > CREATE TABLE number ( > i INTEGER,

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-14 Thread Mike Bayer
ROW() function but then the GeoJson properties have dummy > names ('f1', 'f2', ...). > > Le mar. 14 avr. 2020 à 15:57, Mike Bayer a écrit : >> __ >> does this ST_AsGeoJSON function hardcode itself to look for column names >> "id" and "geom" ? it's not

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-14 Thread Mike Bayer
rchet wrote: > I just found that in fact it is possible to just pass the table name to > ST_AsGeoJson, so the following query works: >> SELECT ST_AsGeoJSON(t) >> FROM t; > > I will try to use this writing in GeoAlchemy2, though I don't know yet how to > translate it in

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-14 Thread Mike Bayer
() constructor: > https://www.postgresql.org/docs/current/sql-expressions.html#SQL-SYNTAX-ROW-CONSTRUCTORS > > > Le mardi 14 avril 2020 00:47:28 UTC+2, Mike Bayer a écrit : >> >> >> On Mon, Apr 13, 2020, at 6:25 PM, Adrien Berchet wrote: >>> Hello th

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-13 Thread Mike Bayer
SQLAlchemy... There should definitely be some way for this to work without doing "*". what if "t" didn't have the columns in that specific order? the "ROW" function seems like what should be used but I don't understand the "column names" issue, is this rega

Re: [sqlalchemy] Filtering self referential relationship

2020-04-13 Thread Mike Bayer
On Mon, Apr 13, 2020, at 11:16 AM, taha wrote: > Hi, > > I have the following model: > > class Categories(Base): >  __tablename__ = "categories" > >  parent_id = db.Column(db.Integer, ForeignKey('categories.id')) >  name = db.Column(db.String(128), nullable=False) >  status =

Re: [sqlalchemy] AbstractConcreteBase and query_expression()

2020-04-09 Thread Mike Bayer
I'm not able to reproduce the issue you describe. Below is an MCVE, can you please modify it to show the failure you are getting? The .foo attribute on B is returned: from sqlalchemy import Column from sqlalchemy import create_engine from sqlalchemy import Integer from sqlalchemy import String

Re: [sqlalchemy] SQL's 'Warning: Null value is eliminated by an aggregate or other SET operation.' overflowing conn.execute(sql)?

2020-04-07 Thread Mike Bayer
>>         (log(var1_neg) - @avg_var1_neg) / @std_var1_neg AS var1_neg, >>         (log(var2_neg) - @avg_var2_neg) / @std_var2_neg AS var2_neg >> INTO output_table >> FROM output_table_temp; >> >> DROP TABLE output_table_temp; >> >> Without SET ANSI_WARNINGS OF

Re: [sqlalchemy] SQL's 'Warning: Null value is eliminated by an aggregate or other SET operation.' overflowing conn.execute(sql)?

2020-04-07 Thread Mike Bayer
this warning is not related to SQLAlchemy it has to do with the structure of SQL you are passing to connection.execute(). some background I found via googling here: https://stackoverflow.com/questions/11384292/warning-null-value-is-eliminated-by-an-aggregate-or-other-set-operation-in-aqua

Re: [sqlalchemy] SQLAlchemy CORE: bindparam()-like solution but for the type_ argument of func.cast()

2020-04-06 Thread Mike Bayer
On Mon, Apr 6, 2020, at 12:31 PM, Massimiliano della Rovere wrote: > > > > Il giorno lun 6 apr 2020 alle ore 16:30 Mike Bayer > ha scritto: >> __ >> >> On Mon, Apr 6, 2020, at 5:42 AM, Massimiliano della Rovere wrote: >>> In SQLAlchemy CORE is the

Re: [sqlalchemy] SQLAlchemy CORE: bindparam()-like solution but for the type_ argument of func.cast()

2020-04-06 Thread Mike Bayer
On Mon, Apr 6, 2020, at 5:42 AM, Massimiliano della Rovere wrote: > In SQLAlchemy CORE is there any way to use bindparam() to late-bind the type_ > parameter of the func.cast function instead of a column? > > I wrote a function returning a "baked query", that extracts settings stored > in a

Re: [sqlalchemy] Re: ObjectDeletedError in master/slave configuration

2020-03-26 Thread Mike Bayer
reset because its a new session instance." > > > > On Thursday, March 26, 2020 at 1:35:14 PM UTC-5, Mike Bayer wrote: >> >> >> On Thu, Mar 26, 2020, at 2:18 PM, Colton Allen wrote: >>> > You can adjust `expire_on_commit` if you're only doing short-t

Re: [sqlalchemy] Re: ObjectDeletedError in master/slave configuration

2020-03-26 Thread Mike Bayer
On Thu, Mar 26, 2020, at 2:18 PM, Colton Allen wrote: > > You can adjust `expire_on_commit` if you're only doing short-term read-only > > actions. > > Can you expand on this? Or link to docs/blog so I can do some research. > Google hasn't helped me so far. Why would I want to expire after

Re: 'alembic current' crashes with stack trace

2020-03-26 Thread Mike Bayer
Somewhere in your model, likely inside of a Table() object, there is a keyword "index" being used which is invalid. Look for that keyword and remove it. On Thu, Mar 26, 2020, at 1:53 PM, Rob Schottland wrote: > Suddenly, I can't get alembic (1.3.3?). alembic history does work, but my > most

Re: [sqlalchemy] AbstractConcreteBase and query_expression()

2020-03-25 Thread Mike Bayer
I don't really know, because AbstractConcreteBase works pretty poorly and it's better to use other patterns. Try this workaround, which I have no idea if it helps in this case: class A(...): # ... @classmethod def __declare_last__(cls): cls.__mapper__.with_polymorphic = ("*",

Re: [sqlalchemy] Cleaning metadata

2020-03-25 Thread Mike Bayer
On Wed, Mar 25, 2020, at 6:27 AM, Javier Collado Jiménez wrote: > Hello, > I'm having a problem trying to cleanup sqlalchemy objects. My application has > a thread which handles DB connections. In some cases the thread dies and I > want to do a cleanup so, next time the thread is started it

Re: Autogenerate with Multi-Tenant

2020-03-20 Thread Mike Bayer
> it works when my schema is 'public', when it matches metadata. my solution > will be to set my schema to 'public' and use this simple env.py. > > thanks, > > brian > > On Friday, March 20, 2020 at 9:49:52 AM UTC-4, Mike Bayer wrote: >> I just realized that you reall

Re: Autogenerate with Multi-Tenant

2020-03-20 Thread Mike Bayer
Thursday, March 19, 2020 at 8:20:06 PM UTC-4, Mike Bayer wrote: >> >> >> On Thu, Mar 19, 2020, at 7:41 PM, Brian Hill wrote: >>> >>> >>> On Thursday, March 19, 2020 at 7:19:08 PM UTC-4, Mike Bayer wrote: >>>> so let me get this straight: &

Re: Autogenerate with Multi-Tenant

2020-03-19 Thread Mike Bayer
On Thu, Mar 19, 2020, at 7:41 PM, Brian Hill wrote: > > > On Thursday, March 19, 2020 at 7:19:08 PM UTC-4, Mike Bayer wrote: >> so let me get this straight: >> >> 1. you have many schemas >> > > yes > >> >> 2. you want to run

Re: Autogenerate with Multi-Tenant

2020-03-19 Thread Mike Bayer
h. you might need to disable the schema translate map when autogenerate runs but try it without doing that first. On Thu, Mar 19, 2020, at 7:09 PM, Brian Hill wrote: > Here's my env.py. Thanks for the help. > Brian > > On Thursday, March 19, 2020 at 5:37:38 PM UTC-4, Mike Bayer wrote

Re: Autogenerate with Multi-Tenant

2020-03-19 Thread Mike Bayer
On Thu, Mar 19, 2020, at 5:30 PM, Brian Hill wrote: > Are there known issues with using autogenerate with multi-tenant > (schema_translate_map)? it's complicated and not one-size-fits-all, if you consider that to be an issue > > My metadata doesn't have a schema and I my >

Re: [sqlalchemy] Custom Compilation

2020-03-18 Thread Mike Bayer
On Wed, Mar 18, 2020, at 1:23 PM, Soumaya Mauthoor wrote: > Hello > > I have two uses cases: > > (1) drop cascade as option > I know I can use custom compilation to add cascade for postgres databases > using this example: >

Re: [sqlalchemy] Warning about using backref with viewonly - how to make a two-way read-only relation?

2020-03-18 Thread Mike Bayer
On Wed, Mar 18, 2020, at 11:42 AM, Mike Bayer wrote: > > > On Wed, Mar 18, 2020, at 11:22 AM, Tony Hignett wrote: >> Hi, >> >> I'm trying to upgrade from 1.2.2 to 1.3.15 and a number of our relations >> have started generating these warnings: >

Re: [sqlalchemy] Warning about using backref with viewonly - how to make a two-way read-only relation?

2020-03-18 Thread Mike Bayer
On Wed, Mar 18, 2020, at 11:22 AM, Tony Hignett wrote: > Hi, > > I'm trying to upgrade from 1.2.2 to 1.3.15 and a number of our relations have > started generating these warnings: > ``` > SAWarning: Setting backref / back_populates on relationship to > refer to viewonly relationship will be

Re: [sqlalchemy] relationship without using a column value (using table name)?

2020-03-16 Thread Mike Bayer
listener(mapper, class_): > discriminator = class_.__tablename__ > class_.comments = relationship( > "EntityType", > primaryjoin= > foreign(remote(EntityType.table_name)) == discriminator > , > viewonly=True > ) > On

Re: [sqlalchemy] association_proxy

2020-03-16 Thread Mike Bayer
I sometimes get a "moderators spam report" for SQLAlchemy and then I know I have to go to the admin interface on the website. I likely approve them really quick before you see them. as far as originals missing i dont know where to go for that. On Mon, Mar 16, 2020, at 12:13 PM, Jonathan

Re: [sqlalchemy] relationship without using a column value (using table name)?

2020-03-14 Thread Mike Bayer
this is called a "Generic foreign key" and it's not really a real relational database pattern. There are a series of examples in https://docs.sqlalchemy.org/en/13/orm/examples.html#module-examples.generic_associations that show four different ways to achieve this pattern, one of which is the

Re: [sqlalchemy] association_proxy

2020-03-13 Thread Mike Bayer
On Wed, Mar 11, 2020, at 1:50 PM, Damian Yurzola wrote: > Folks: > > I'm trying to achieve the following. > I have a legacy table (Parent), which has a good foreign key to a tiny table > that complements it (Child). > > For the use case, querying Parent without joining with Child is not >

Re: [sqlalchemy] How can I use bulk_save_objects when I know the primary key?

2020-03-12 Thread Mike Bayer
On Thu, Mar 12, 2020, at 9:51 PM, James Fennell wrote: > Hey all! I'm having a problem using the bulk_save_objects function. > ** > *Background*: I'm working on an application that updates state in a database > from an external feed. The process is: I read the feed, convert the data into >

Re: [sqlalchemy] How do I use unnest and select using the Query API?

2020-03-12 Thread Mike Bayer
unnest is a fancy thing that isn't easily supported by SQLAlchemy right now. there's a recipe at https://github.com/sqlalchemy/sqlalchemy/issues/3566#issuecomment-441931333 which hopefully is still in working order, you'd have to work with that for now. On Thu, Mar 12, 2020, at 8:31 PM, Shyam

Re: [sqlalchemy] Testing with a fake read replica

2020-03-11 Thread Mike Bayer
he test suite right? if it works, it works > > On Wednesday, March 11, 2020 at 12:34:12 PM UTC-5, Mike Bayer wrote: >> >> >> On Wed, Mar 11, 2020, at 12:44 PM, Colton Allen wrote: >>> Hi, >>> >>> Before we talk about the read-replica, let's tal

Re: [sqlalchemy] Testing with a fake read replica

2020-03-11 Thread Mike Bayer
On Wed, Mar 11, 2020, at 12:44 PM, Colton Allen wrote: > Hi, > > Before we talk about the read-replica, let's talk about the test suite as it > is. I have a sessionmaker in my test suite configured to use an external > transaction. Basically identical to this: >

Re: [sqlalchemy] Closing all sqlalchemy sessions, connections, pools, metadata

2020-03-09 Thread Mike Bayer
On Mon, Mar 9, 2020, at 5:40 PM, Don Smiley wrote: > In unit testing with multiple configurations, I am having trouble closing out > everything to go on to the next iteration. For example, the test creates a > class Address. I get the following kind of error: > > ``` >

Re: Invoke commands with custom env.py from library

2020-03-05 Thread Mike Bayer
ere is truly something blocking ScriptDirectory from working this way, maybe I'd suggest monkeypatching, but script_directory and version_locations look separate to me and are handled separately all the way from ScriptDirectory.from_config(). > > On Thursday, March 5, 2020 at 12:21:

Re: Invoke commands with custom env.py from library

2020-03-05 Thread Mike Bayer
ommand is targeting the project "foo"'s local > migrations/versions folder > > The specifics of the above are just based on my knowledge of alembic, so if > there's another process i could be doing where env.py isn't "invoked" so much > as the above code block is ju

Re: [sqlalchemy] Memory management in sqlalchemy

2020-03-05 Thread Mike Bayer
On Thu, Mar 5, 2020, at 10:17 AM, Adrien Blin wrote: > I tried strong referencing the objects stored in the session using : > > *def *strong_reference_session(session): > @event.listens_for(session, "pending_to_persistent") > @event.listens_for(session, "deleted_to_persistent") >

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