[sqlalchemy] Security Implications of Directly Executing Queries Compiled to Strings

2019-03-07 Thread Seth P
Someone wrote a server that blindly executes SQL strings? Oy. Google around for why that is a terrible idea. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable

Re: [sqlalchemy] Re: ORM: read from view but write into separate table

2018-12-05 Thread Seth P
My 2c about table design (not SQLA): I would suggest having a child with just id, a parent table with just id and child_id (foreign key to child.id), and then store additional "versioned" data in separate parent_history and child_history tables that have foreign keys only to their respective

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

2018-09-01 Thread Seth P
In relationship(), foreign_keys refers to the field in the source table, not the destination. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See

[sqlalchemy] SQLAlchemy and Python 3.7 data classes

2018-02-28 Thread Seth P
I don't have a well-formulated question, but reading PEP 557 (https://www.python.org/dev/peps/pep-0557/) made me wonder if SQLAlchemy declarative models would/should in some way be Python 3.7 data classes. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

[sqlalchemy] Re: SQLAlchemy 1.2.0 released

2018-01-03 Thread Seth P
Perhaps this isn't the right place to ask, but do you know when https://anaconda.org/conda-forge/sqlalchemy will be updated to 1.2.0? -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal,

[sqlalchemy] Postgres 10 identity keyword

2017-10-08 Thread Seth P
Apologies if I missed something, but does SQLAlchemy (1.2.0?) support the new Postgres 10 identity keyword (https://blog.2ndquadrant.com/postgresql-10-identity-columns/)? -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code,

[sqlalchemy] Re: DELETE CASCADE does not work when foreing key can be nulleable

2017-07-21 Thread Seth P
You're naming both tables 'parent_table'. Perhaps that is messing things up? -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See

Re: [sqlalchemy] quote=False for all columns in table

2017-07-01 Thread Seth P
Perfect. Thank you! On Friday, June 30, 2017 at 5:41:33 PM UTC-4, Mike Bayer wrote: > > > from sqlalchemy import Column, String, Integer, create_engine > from sqlalchemy.orm import Session > from sqlalchemy.ext.declarative import declarative_base > from sqlalchemy import event > > Base =

Re: [sqlalchemy] quote=False for all columns in table

2017-06-30 Thread Seth P
Jun 30, 2017 at 4:31 PM, Seth P <set...@outlook.com > > wrote: > > Is there a way (when using declarative) to specify that all the columns > of a > > table should use quote=False without specifying it explicitly for each > > column? > > Easiest is just to call

[sqlalchemy] quote=False for all columns in table

2017-06-30 Thread Seth P
Is there a way (when using declarative) to specify that all the columns of a table should use quote=False without specifying it explicitly for each column? I've tried setting __table_args__ = { 'quote_schema': False, 'quote': False }, but that just affects the schema and table name, not the

Re: [sqlalchemy] ORM and table with no primary key

2016-10-17 Thread Seth P
On Monday, October 17, 2016 at 3:58:36 PM UTC-4, Mike Bayer wrote: > > that error is there right now because we don't emit the "col IS NULL" > SQL within that section of the persistence code. > > took me a long time to find the history on this because I thought it had > been discussed but looks

[sqlalchemy] ORM and table with no primary key

2016-10-17 Thread Seth P
I realize that the orm really wants/needs a table to have a primary key: http://docs.sqlalchemy.org/en/rel_1_1/faq/ormconfiguration.html?#how-do-i-map-a-table-that-has-no-primary-key Alas I have to deal with an existing table with no primary key. That said, it does have a unique constraint on a

Re: [sqlalchemy] Sequence schema

2016-10-17 Thread Seth P
On Monday, October 17, 2016 at 11:24:43 AM UTC-4, Mike Bayer wrote: > > However, I don't see how the ordered attributes fixes anything in terms > of mixins. If a mixin wants its columns at the beginning, or the end, > all of that can be upended by the presence of other mixins and those >

Re: [sqlalchemy] Sequence schema

2016-10-17 Thread Seth P
On a related note, is there something like after_create events for indexes and sequences? There doesn't seem to be. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable

Re: [sqlalchemy] Sequence schema

2016-10-17 Thread Seth P
On Sunday, October 16, 2016 at 10:09:00 AM UTC-4, Mike Bayer wrote: > > > > The simplest way is probably to set the creation order of the column to > be at the top: > > col = Column(...) > col._creation_order = -10 Great. I will use _creation_order. Thanks. By the way, in view of PEP 520

[sqlalchemy] Sequence schema

2016-10-14 Thread Seth P
I have a mixin of the following form class MyMixin(object): idx = sa.Column(sa.Integer, sa.Sequence('idx_seq', schema=???, optional=True), primary_key=True) ... I would like the sequence to have the same schema as the table into which MyMixin will be mixed. I realize I could make idx

Re: [sqlalchemy] Feedback appreciated

2016-10-03 Thread Seth P
ike...@zzzcomputing.com> Sent: Monday, October 3, 2016 5:54 PM Subject: Re: [sqlalchemy] Feedback appreciated To: <sqlalchemy@googlegroups.com> On 10/03/2016 05:21 PM, Seth P wrote: > > > On Friday, September 30, 2016 at 7:09:09 PM UTC-4, Mike Bayer wrote: > > the bin

Re: [sqlalchemy] Feedback appreciated

2016-10-03 Thread Seth P
On Friday, September 30, 2016 at 7:09:09 PM UTC-4, Mike Bayer wrote: > > the bind_expression() hook is here to allow you to re-render the > expression. assuming value-bound bindparam() objects (e.g. not like > you'd get with an INSERT or UPDATE usually), the value should be present > and you

Re: [sqlalchemy] Feedback appreciated

2016-09-30 Thread Seth P
On Thursday, September 29, 2016 at 9:45:24 AM UTC-4, Mike Bayer wrote: > > you can add your own types to do these things also, especially > read-only, just make any subclass of UserDefinedType and apply whatever > result-row handling is needed for how cx_Oracle is returning the data. > > The

Re: [sqlalchemy] Feedback appreciated

2016-09-28 Thread Seth P
On Wednesday, September 28, 2016 at 5:43:04 PM UTC-4, Mike Bayer wrote: > > looks incredibly difficult. I'm not really about to have the resources > to work with a type that awkward anytime soon, unfortunately. If it > could be made to be a drop-in for 1.1's ARRAY feature, that would be >

Re: [sqlalchemy] Feedback appreciated

2016-09-28 Thread Seth P
On Wednesday, September 28, 2016 at 10:16:20 AM UTC-4, Mike Bayer wrote: > > > So illustrating VARRAY round trip on cx_oracle is the first step. > It looks like cx_Oracle supports reading varrays, but supports writing them only as column literals, not as bound parameters. The following code

[sqlalchemy] Re: SQLAlchemy - Bulk update using sqlalchemy core table.update() expects all columns in the values data

2016-09-28 Thread Seth P
Oops, I missed that this is an UPDATE rather than an INSERT. Setting the missing columns to None probably isn't what you want. On Wednesday, September 28, 2016 at 9:08:00 AM UTC-4, Seth P wrote: > > Can't you include the missing columns in your dictionary with None values? > -- You

Re: [sqlalchemy] Feedback appreciated

2016-09-28 Thread Seth P
On Friday, August 23, 2013 at 3:52:54 PM UTC-4, Konsta Vesterinen wrote: > > > > On Friday, August 23, 2013 1:52:41 AM UTC+3, Michael Bayer wrote: > > >> 2. ScalarListType vs. Postgresql ARRAY ? same/better? should SLT use >> ARRAY on a PG backend ? >> > > Hmm I'm not sure about this yet.

[sqlalchemy] Re: SQLAlchemy - Bulk update using sqlalchemy core table.update() expects all columns in the values data

2016-09-28 Thread Seth P
Can't you include the missing columns in your dictionary with None values? -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to

Re: [sqlalchemy] How to bulk-insert millions of values into Oracle

2016-09-26 Thread Seth P
Thanks. I guess my confusion is that the example at http://docs.sqlalchemy.org/en/latest/core/tutorial.html#executing-multiple-statements uses an array of dictionaries, not of unlabeled tuples. Meanwhile I ended up using Oracle's sqlldr, which seems to get the job done, though is much more

[sqlalchemy] How to bulk-insert millions of values into Oracle

2016-09-23 Thread Seth P
The answer to this is probably RTFM, but I can't figure it out. Suppose I have a declarative model of the form class MyModel(Model): idx = sa.Column(sa.Integer, primary_key=True) c1 = sa.Column(sa.Float) c2 = sa.Column(sa.Integer) ... c10 = sa.Column(sa.Float) And a list of

[sqlalchemy] sa.DateTime(timezone=True) not emitting TIMESTAMP WITH TIMEZONE for Oracle

2016-09-22 Thread Seth P
The documentation for DateTime, http://docs.sqlalchemy.org/en/latest/core/type_basics.html?highlight=datetime#sqlalchemy.types.DateTime, states Parameters:*timezone* – boolean. If True, and supported by the backend, will produce ‘TIMESTAMP WITH TIMEZONE’. For backends that don’t support

Re: [sqlalchemy] Using literals in ORM update/delete query

2016-09-13 Thread Seth P
FWIW, this sounds similar to the problems you and I had (separately) a couple of years ago: https://groups.google.com/forum/#!topic/sqlalchemy/kv7BqWZr9KQ https://groups.google.com/forum/#!topic/sqlalchemy/k_9ZGI-e85E On Monday, September 12, 2016 at 5:39:37 PM UTC-4, Thierry Florac wrote: > > I

[sqlalchemy] kdb+/q dialect

2016-09-08 Thread Seth P
Has anyone written a SQLAlchemy dialect for kdb+/q? I realize q isn't exactly SQL, but I figure if it's possible to write a dialect for Pandas tables (https://bitbucket.org/zzzeek/calchipan) it should be possible to do so for q. -- You received this message because you are subscribed to the

Re: [sqlalchemy] Column order with declarative base and @declared_attr

2016-08-25 Thread Seth P
order first. So it would be of limited use for there to be an ordering under @declared_attr. On 08/25/2016 02:46 PM, Seth P wrote: > I was just bitten by this issue. Is it still the case that there is no way to > specify the order of two columns declared in a mixin using @declared_attr?

Re: [sqlalchemy] Column order with declarative base and @declared_attr

2016-08-25 Thread Seth P
I was just bitten by this issue. Is it still the case that there is no way to specify the order of two columns declared in a mixin using @declared_attr? -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop

Re: [sqlalchemy] Implicit join condition

2016-07-13 Thread Seth P
that has a (unique) ForeignKey to A.) On Wednesday, July 13, 2016 at 2:06:55 PM UTC-4, Mike Bayer wrote: > > > > On 07/13/2016 01:04 PM, Seth P wrote: > > Thank you, as always, for the quick and detailed response. > > > > With the join to the subquery that's o

Re: [sqlalchemy] Implicit join condition

2016-07-13 Thread Seth P
to the function, i.e. join_to_min_a(q, field_to_join_to_A_id). On Wednesday, July 13, 2016 at 12:16:52 PM UTC-4, Mike Bayer wrote: > > > > On 07/13/2016 02:29 AM, Seth P wrote: > > [Apologies for posting an incomplete version of this post earlier. > > Please ignore it.] > > &g

[sqlalchemy] Re: Implicit join condition

2016-07-13 Thread Seth P
Actually, taking a closer look, the sql generated for query 5 doesn't look correct (or at least not what I want), since it isn't joining max_a_id with anything. On Wednesday, July 13, 2016 at 2:29:34 AM UTC-4, Seth P wrote: > > [Apologies for posting an incomplete version of this post e

[sqlalchemy] Implicit join condition

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

[sqlalchemy] Implicit join conditions

2016-07-12 Thread Seth P
Apologies if this is documented and I missed it. If B has a ForeignKey (and relationship) to A (e.g. B.a_id -> A.id), then I can write query(B.b_num).join(A) without specifying the condition, and SQLAlchemy will figure out the join automatically. [See query 0 in the code below.] It will

Re: [sqlalchemy] engine.execute() slow with parameterized queries?

2014-05-13 Thread Seth P
it to happen and how. It likely would require some subclassing and possibly monkey patching. On May 12, 2014, at 8:23 PM, Seth P spad...@gmail.com javascript: wrote: pymssql produces the same results as pyodbc. So it looks like a SQL Server issue. On Monday, May 12, 2014 8:06:08 PM UTC

[sqlalchemy] engine.execute() slow with parameterized queries?

2014-05-12 Thread Seth P
After tracking down some extreme slowness in loading a one-to-many relationship (e.g. myobject.foobars), I seem to have isolated the issue to engine.execute() being much slower with parameterized queries than with explicit queries. The following is actual code and output for loading 10,971

[sqlalchemy] Re: engine.execute() slow with parameterized queries?

2014-05-12 Thread Seth P
Forgot to mention that I'm running SQLAlchemy 0.9.4 on 64-bit Python 3.4.0 on Windows. On Monday, May 12, 2014 3:48:44 PM UTC-4, Seth P wrote: After tracking down some extreme slowness in loading a one-to-many relationship (e.g. myobject.foobars), I seem to have isolated the issue

Re: [sqlalchemy] engine.execute() slow with parameterized queries?

2014-05-12 Thread Seth P
://stackoverflow.com/questions/1171166/how-can-i-profile-a-sqlalchemy-powered-application/1175677#1175677 On May 12, 2014, at 3:48 PM, Seth P spad...@gmail.com javascript: wrote: After tracking down some extreme slowness in loading a one-to-many relationship (e.g. myobject.foobars), I seem

Re: [sqlalchemy] engine.execute() slow with parameterized queries?

2014-05-12 Thread Seth P
, parameterized_runtime)) On Monday, May 12, 2014 6:40:48 PM UTC-4, Michael Bayer wrote: On May 12, 2014, at 6:33 PM, Seth P spad...@gmail.com javascript: wrote: Is it possible that the (primary key index (which is a composite index that begins with gvkey, and is the only index on the table) isn't being

Re: [sqlalchemy] engine.execute() slow with parameterized queries?

2014-05-12 Thread Seth P
to plug in parameters client-side. I presume not trivial to add to SQLAlchemy? I don't see such an option for pyodbc. On Monday, May 12, 2014 7:09:08 PM UTC-4, Seth P wrote: Yep, it's not a SQLAlchemy issue. The following code demonstrates the problem with direct pyodbc access. import pyodbc

Re: [sqlalchemy] engine.execute() slow with parameterized queries?

2014-05-12 Thread Seth P
Fair enough. I'll take a look at pymssql, though I suspect it may be a SQL Server rather than a driver issue. On Monday, May 12, 2014 7:50:03 PM UTC-4, Michael Bayer wrote: On May 12, 2014, at 7:35 PM, Seth P spad...@gmail.com javascript: wrote: Looks like other people have encountered

Re: [sqlalchemy] engine.execute() slow with parameterized queries?

2014-05-12 Thread Seth P
pymssql produces the same results as pyodbc. So it looks like a SQL Server issue. On Monday, May 12, 2014 8:06:08 PM UTC-4, Seth P wrote: Fair enough. I'll take a look at pymssql, though I suspect it may be a SQL Server rather than a driver issue. On Monday, May 12, 2014 7:50:03 PM UTC-4

[sqlalchemy] Problem with _compiler_dispatch() call?

2014-05-05 Thread Seth P
I get the following error when trying to create_all() in a sqlite database: TypeError: _compiler_dispatch() missing 1 required positional argument: 'visitor' Looking at annotation.py and visitors.py, all instances of _compiler_dispatch() do indeed appear to expect a 'visitor' argument, which

[sqlalchemy] Re: Problem with _compiler_dispatch() call?

2014-05-05 Thread Seth P
:07:50 PM UTC-4, Seth P wrote: I get the following error when trying to create_all() in a sqlite database: TypeError: _compiler_dispatch() missing 1 required positional argument: 'visitor' Looking at annotation.py and visitors.py, all instances of _compiler_dispatch() do indeed appear

[sqlalchemy] How to order a many-to-many association_proxy?

2014-02-27 Thread Seth P
Apologies if I'm missing this is the docs somewhere, but I can't figure it out. Suppose I have a many-to-many relationship between A and B, and that I'd like have the various B's that a particular A points to ordered by B.ordinal (i.e. in the examples below, I'd like A.bs to be sorted to

[sqlalchemy] Re: How to order a many-to-many association_proxy?

2014-02-27 Thread Seth P
Just noticed that I had a typo, where I wrote order_by=b.ordinal rather than order_by=b.order. But changing it to order_by=b.order still gives: AttributeError: 'RelationshipProperty' object has no attribute 'order' -- You received this message because you are subscribed to the Google Groups

[sqlalchemy] How to order many-to-many association_proxy?

2014-02-27 Thread Seth P
How do I get the objects pointed to by a many-to-many association proxy to be sorted? In the example below, adding order_by=b.order to the backref() produces AttributeError: 'RelationshipProperty' object has no attribute 'order', and adding order_by=b.order produces AttributeError: 'Table'

Re: [sqlalchemy] How to order a many-to-many association_proxy?

2014-02-27 Thread Seth P
Thank you. This was very helpful. One non-trivial thing that stumped me for a while is that if B is derived from a B_base using joined-table inheritance, and the order variable is in the base table B_base, then it seems one must include B_base explicitly -- as highlighted below. from

Re: [sqlalchemy] How to order a many-to-many association_proxy?

2014-02-27 Thread Seth P
, February 27, 2014 9:26:31 PM UTC-5, Michael Bayer wrote: On Feb 27, 2014, at 9:23 PM, Seth P spad...@gmail.com javascript: wrote: Thank you. This was very helpful. One non-trivial thing that stumped me for a while is that if B is derived from a B_base using joined-table inheritance

[sqlalchemy] session.is_modified() and floating-point numbers

2013-11-19 Thread Seth P
I have an issue where, I believe due to floating-point representation issues, reassigning the same value to a floating-point field causes SQLAlchemy to think the value has been modified, and therefore emits a gratuitous UPDATE. (This is particularly problematic when using the versioning mixin,

Re: [sqlalchemy] session.is_modified() and floating-point numbers

2013-11-19 Thread Seth P
problem, the recipe fixes if you just say this: class InexactFloat(TypeDecorator): impl = Float def compare_values(self, x, y): return bool(x == y) On Nov 19, 2013, at 8:30 PM, Michael Bayer mik...@zzzcomputing.comjavascript: wrote: On Nov 19, 2013, at 8:10 PM, Seth

[sqlalchemy] overriding lazy loading?

2013-09-12 Thread Seth P
Is it possible to override the default loading strategy of a relationship at run-time? For example, I have a relationship that I almost always want to load with lazy='subquery' -- and so I set that as the default loading strategy in the relationship definition -- but in one instance, when I

Re: [sqlalchemy] overriding lazy loading?

2013-09-12 Thread Seth P
D'oh! I did, though for some reason it didn't occur to me that I could specify .override(lazyload('points')) to override the relationship's default lazy='subquery'. Works like a charm. Thank you. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To

[sqlalchemy] joined-table inheritance and ambiguous foreign keys

2013-07-24 Thread Seth P
The code below produces the error message below. How do I tell SQLAlchemy that the inheritance join condition should be b.id == a.id rather than b.parent_a_id == a.id? (I would think the primary_key=True could be a hint...) I can't figure it out from the documentation. class A(Base):

Re: [sqlalchemy] joined-table inheritance and ambiguous foreign keys

2013-07-24 Thread Seth P
Thank you. On Wed, Jul 24, 2013 at 5:51 PM, Michael Bayer mike...@zzzcomputing.comwrote: its a mapper arg called inherit_condition: __mapper_args__ = {inherit_condition: id==A.id} On Jul 24, 2013, at 3:42 PM, Seth P spadow...@gmail.com wrote: The code below produces the error message

[sqlalchemy] Versioned mixin and backref

2013-06-19 Thread Seth P
The Versioned mixin described in http://docs.sqlalchemy.org/en/rel_0_8/orm/examples.html#versioned-objects (which I renamed VersionedMixin, but is otherwise the same) has what I would consider an unintuitive and undesirable interaction with backref: if C references A with a backref, adding a

[sqlalchemy] Bug in query with multiple joins when using joined inheritance?

2013-06-14 Thread Seth P
I've encountered what I believe to be a bug in SQLAlchemy (versions 0.8.0 and 0.8.1) in a query that joins class/tables that use joined inheritance. In the code below, I would expect the three queries to produce the same output, namely [u'CCC'], but the first one gives a different (incorrect)