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

2017-05-19 Thread Simon King
urn self unchanged. So "eq_(tablenames[0].upper(), tablenames[0].lower())" should succeed. I guess the intention of the test is to check that the inspection routines return a quoted_name with quote=True. Hope that helps, Simon -- SQLAlchemy - The Python SQL Toolkit and Object Rel

Re: [sqlalchemy] Composite column with null property

2017-05-12 Thread Simon King
return self._money return None Hope that helps, Simon -- 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 http://stackoverflow.

Re: [sqlalchemy] Bulk Lazy Loader for relationships

2017-05-03 Thread Simon King
ook at the original instance, rather than the one inside the loop, isn't it? Again, thanks a lot for sharing, Simon -- 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] eager loading relationships after an initial query?

2017-04-25 Thread Simon King
On Mon, Apr 24, 2017 at 10:26 PM, Jonathan Vanasco wrote: > > On Monday, April 24, 2017 at 4:28:22 PM UTC-4, Mike Bayer wrote: >> >> yeah just load the object again w/ the eagerloads option you want. > > > > Thanks. I was hoping there was a way to just say

Re: [sqlalchemy] How to pass list of columns into query method.

2017-04-05 Thread Simon King
) for name in col_names] q = session.query(*cols).limit(100) for row in q: print row Simon On Wed, Apr 5, 2017 at 1:20 PM, Mayank Soni <mayank.so...@gmail.com> wrote: > Thanks Simon for response. > Actually column names I am getting from user interface based on user > selection that i

Re: [sqlalchemy] How to pass list of columns into query method.

2017-04-05 Thread Simon King
t '['dise_code_01', 'district_name_02', > 'block_name_03', 'cluster_name_04', 'village_name_05'] > > Please help me out from this error. > add_columns expects each column to be supplied as a separate argument, so you at least need: q = session.query(AAA).add_columns(*col_list) ...to unpack

Re: [sqlalchemy] Attribute history for columns with no explicit default

2017-03-13 Thread Simon King
On Mon, Mar 13, 2017 at 1:50 PM, mike bayer <mike...@zzzcomputing.com> wrote: > > > On 03/13/2017 08:34 AM, Simon King wrote: >> >> Hi, >> >> I'm not sure if the problem I've got is a bug or intended behaviour. >> Here's a test script: >> >&g

Re: [sqlalchemy] Looks like there is no event to catch "before" a rollback happens

2017-03-10 Thread Simon King
vent from which it > can get the state of the objects and their history before the rollback. > Could you collect the necessary data using the before_attach or after_attach events, rather than before_flush? Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sql

Re: [sqlalchemy] Perfoming join on multiple tables dynamically

2017-03-06 Thread Simon King
kes sense if the same ID exists in both child tables. Simon -- 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 http://stackoverflow.com/help/mcve for a fu

Re: [sqlalchemy] ORM: Implementing abstract base class that generates auxiliary tables for each child class

2017-02-17 Thread Simon King
nts, but I haven't tried it. You could investigate the mapper_configured event: http://docs.sqlalchemy.org/en/latest/orm/events.html#sqlalchemy.orm.events.MapperEvents.mapper_configured The code would look something like: @event.listens_for(TreeNode, 'mapper_configured', propagate=True) def receive_mapper_configure

Re: [sqlalchemy] Re: Retrieving Objects from DB

2016-12-16 Thread 'Simon Dold' via sqlalchemy
Nice,I feel really stupid now but thank you very much, will verify this later. Best, Simon.. Am 16.12.2016 6:42 nachm. schrieb "Jonathan Vanasco" <jonat...@findmeon.com >: > > > On Friday, December 16, 2016 at 12:14:11 PM UTC-5, Simon Moon wrote: >> >> >

[sqlalchemy] Re: Retrieving Objects from DB

2016-12-16 Thread 'Simon Moon' via sqlalchemy
class Machine(Base): __tablename__='machine' id = Column(Integer, primary_key=True) name = Column(String(250), nullable=False) comment= Column(String(250)) tags = Column(String(250), nullable=True) class GeneralMeasurementData(Base):

[sqlalchemy] Retrieving Objects from DB

2016-12-16 Thread 'Simon Moon' via sqlalchemy
.. session.add(gData) session.commit() gData has a foreign key on Machine.id. It seems m is not a Machine object. I think it should be clear what I want to do, but I can't figure what the SQLAlchemy way would be to do it Is there a way to do this??? Best Simon -- SQL

Re: [sqlalchemy] SQLAlchemy dedicated read-server pooling

2016-12-15 Thread Simon King
On Thu, Dec 15, 2016 at 10:00 AM, Simon King <si...@simonking.org.uk> wrote: > On Thu, Dec 15, 2016 at 2:07 AM, Matt <m...@ramwise.com> wrote: >> >> >> On Wednesday, December 14, 2016 at 3:58:19 PM UTC+1, Mike Bayer wrote: >>> >>> >&

Re: [sqlalchemy] SQLAlchemy dedicated read-server pooling

2016-12-15 Thread Simon King
y/blob/master/flask_sqlalchemy/__init__.py#L747 It looks like you should be able to override the create_session method (which actually returns a session *factory*) to return your custom factory instead. Hope that helps, Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Map

Re: [sqlalchemy] Set/clear mapping for some tables only

2016-11-29 Thread Simon King
to use any of these packages if you don't want to. You can create your own SQLAlchemy session at the beginning of each request, and commit or roll it back at the end. Simon On Tue, Nov 29, 2016 at 3:04 AM, Srikanth Bemineni <bemineni.srika...@gmail.com> wrote: > Hi Mike, > > I am using pyramid_

Re: [sqlalchemy] Set/clear mapping for some tables only

2016-11-28 Thread Simon King
call to mark_changed after creating your tables.Search for "mark_changed" on this page: https://pypi.python.org/pypi/zope.sqlalchemy Hope that helps, Simon On Sun, Nov 27, 2016 at 2:24 PM, Srikanth Bemineni <bemineni.srika...@gmail.com> wrote: > Hi Mike, > > I even

Re: [sqlalchemy] Column value determined as a function return on INSERT

2016-11-18 Thread Simon King
-sensitive-default-functions I haven't tested this at all, but perhaps you could use something like: def getdefaultid(context): return (select([func.max(APIResponse.version) + 1]) .where(APIResponse.id == context.current_parameters['id'])) Hope that helps, Simon On Fri, Nov 18, 2016

Re: [sqlalchemy] How to run multiple statements/operations in a single transaction ?

2016-11-18 Thread Simon King
saction. > This section of the docs deals with transactions in SQLAlchemy Core: http://docs.sqlalchemy.org/en/latest/core/connections.html#using-transactions You can execute as many statements as you like between starting and committing the transaction. Hope that helps, Simon -- SQLAlch

Re: [sqlalchemy] Setting key of hybrid_property to attribute name rather than function name

2016-11-11 Thread Simon King
won't have a "born" attribute. Anyway, to answer your original question, would it be sufficient to update the __name__ attribute of your instance_get function inside json_property? ie. def json_property(json_column, name, type_=None): def instance_get(self): return getattr(sel

Re: [sqlalchemy] Setting key of hybrid_property to attribute name rather than function name

2016-11-11 Thread Simon King
881 # Raises AttributeError > since hybrid_property uses instance_get as the name > I think your code is basically fine, you've just got a mistake on the last line. Presumably you meant to query Person, not Person.born? assert session.query(Person).one().born == 1881 hybrid_property does't care about the name of the

Re: [sqlalchemy] Re: One to One relationship

2016-11-11 Thread Simon King
itions: teacher = relationship( "Teacher", foreign_keys=[teacher_id], back_populates="related_student" ) related_student = relationship( "Student", uselist=False, foreign_keys=[id] # <-- this is incorrect

Re: [sqlalchemy] Flask SQLalchemy sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) column todos.user_id does not exist

2016-11-11 Thread Simon King
don't get it. And I want to add more models such > as Tag, Project, Progress, Members. This error is coming from postgres. SQLAlchemy has generated a query that includes the column "todos.user_id", but postgres is reporting that the column doesn't exist. Are you sure that your table def

Re: [sqlalchemy] Re: Orm, join 1 row from many2many table when querying

2016-11-10 Thread Simon King
Whoops, yes, you're right. You should be able to simplify the relationship definition to a simple "primaryjoin" clause, no need for any of the "secondary" stuff. Simon On Thu, Nov 10, 2016 at 1:41 PM, Dorian Hoxha <dorian.ho...@gmail.com> wrote: > Note that you'

Re: [sqlalchemy] Orm, join 1 row from many2many table when querying

2016-11-10 Thread Simon King
print ' ', thing.current_user_like if __name__ == '__main__': import sys args = sys.argv[1:] echo = False if '-d' in args: echo = 'debug' elif '-v' in args: echo = True test(echo) #### Simon On Thu, Nov 10, 2016 at 11:20 AM, Dorian Hoxha

Re: [sqlalchemy] Orm, join 1 row from many2many table when querying

2016-11-10 Thread Simon King
_like" relationship, or how to populate it during a query? In general, if you want a relationship to be populated during a query, you use one of the loader options such as joinedload or subqueryload: http://docs.sqlalchemy.org/en/latest/orm/loading_relationships.html#using-loader-strategies-l

Re: [sqlalchemy] postgresql array column, fetch only_load() element by index

2016-11-08 Thread Simon King
If you have an SQLAlchemy session, you would write this: session.query(Model.array[1]).all() Assuming your "Model.query" is a shorthand for "session.query(Model)", you might be able to use: Model.query.with_entities(Model.array[1]).all() Simon On Tue, Nov 8, 2016

Re: [sqlalchemy] .count() hangs indefinitely

2016-11-04 Thread Simon King
rl-C the process, what does the backtrace look like? Simon -- 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 http://stackoverflow.com/help/mcve for a full

Re: [sqlalchemy] Handy package to debug flask+sqlalchemy+orm (flask_sqla_debug)

2016-10-31 Thread Simon King
Ah, that too looks very interesting, thanks for pointing it out. It looks like it provides the sort of split that I was talking about. I'll definitely investigate that one further. Thanks, Simon On Mon, Oct 31, 2016 at 11:17 AM, Thierry Florac <tflo...@gmail.com> wrote: > Hi, > &

Re: [sqlalchemy] Handy package to debug flask+sqlalchemy+orm (flask_sqla_debug)

2016-10-31 Thread Simon King
On Sun, Oct 30, 2016 at 9:36 PM, Alfred Perlstein <alfred.perlst...@gmail.com> wrote: > Hello, > > I wanted to start this out with a big thanks to the community, especially > Mike Bayer, Simon King, and Jonathan Vanasco. > > A few weeks ago I asked for help on debugging

Re: [sqlalchemy] Inject/Extend an attribute onto all objects in a Session?

2016-10-28 Thread Simon King
> On 28 Oct 2016, at 21:47, Jonathan Vanasco <jvana...@gmail.com> wrote: > > oh great! `session.info["request"]` solved all my problems quite nicely. i > integrated that my pipy sessions manager. > > Simon, thanks. Looking at your code, I recall that `dbsessi

Re: [sqlalchemy] Inject/Extend an attribute onto all objects in a Session?

2016-10-28 Thread Simon King
ion, 'dbsession', reify=True) I really ought to be using session.info rather than sticking a new property directly on the session object... Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Co

Re: [sqlalchemy] Simple SQLAlchemy hiearchical inheritance model

2016-10-26 Thread Simon King
be simpler. I don't think you'd need another "status" column, as your "type" column will already contain either "verified_user" or "invited_user". To change the class, you'd have to UPDATE the type column and expunge any instances. In my opinion, having a sin

Re: [sqlalchemy] Handling "generic" relations

2016-10-20 Thread Simon King
ciations/generic_fk.html. As the comment at the top of that file says, the database schema isn't ideal because there is no database-level foreign key constraint on the Address.attached_to column, so ensuring database consistency is more difficult. If that isn't a concern in your application, you c

Re: [sqlalchemy] sqlalchemy import issue in powa web

2016-10-14 Thread Simon King
oup: http://powa.readthedocs.io/en/latest/support.html. Try starting the python CLI and typing: import sqlalchemy print sqlalchemy.__file__ It should point to an __init__.py file in a directory that also contains a dialects/postgresql/__init__.py file. If it doesn't, you'd need to figure out why.

Re: [sqlalchemy] Selective logging using the ORM for a single thread. Can't do it, therefore can't debug our app.

2016-10-12 Thread Simon King
, 'before_cursor_execute', named=True) def receive_before_cursor_execute(**kw): if DEBUGGING: print kw['statement'] Simon On Wed, Oct 12, 2016 at 8:13 AM, Alfred Perlstein <alfred.perlst...@gmail.com> wrote: > Mike, > > I'm trying to find a nice way to say that this doesn

Re: [sqlalchemy] Question regarding detached object

2016-10-07 Thread Simon King
o any objects that had already been loaded become detached. Then the exception handler mechanism takes over and renders the appropriate exception view. If your exception view tries to access any not-yet-loaded properties on those detached objects, you’ll get the above error. Simon -- You re

Re: [sqlalchemy] How to implement SQL level expression for this hybrid property?

2016-10-03 Thread Simon King
On Mon, Oct 3, 2016 at 11:43 AM, Jinghui Niu <niujing...@gmail.com> wrote: > This really helps. Thank you Simon! I still have a couple of smaller > questions. > >> When you access .fullname, the "self" parameter is now the >> *class*, so self.firstname an

Re: [sqlalchemy] How to implement SQL level expression for this hybrid property?

2016-10-03 Thread Simon King
y, but you'll need to accept that you can't simply use your currency_exchange_rate_lookup dictionary as it is. Perhaps if you could give an example of a query you'd like to write using this property, and the sort of SQL you'd expect to see generated, we might be able to help with the implem

Re: [sqlalchemy] How to implement SQL level expression for this hybrid property?

2016-10-03 Thread Simon King
the example in the docs you are referring to is this one: @hybrid_property def fullname(self): return self.firstname + " " + self.lastname In this example, "User.fullname" is precisely equivalent to: User.firstname + " " + User.lastname User.firstnam

Re: [sqlalchemy] How can I programmatically give a hybrid_property its name?

2016-09-29 Thread Simon King
op = hybrid_property(fget, fset=fset, expr=expr) # Add the hybrid property to a class under the name "propertyname" setattr(SomeClass, 'propertyname', prop) Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group.

Re: [sqlalchemy] AutomapBase without binding engine/tables individually?

2016-09-20 Thread Simon King
h I haven't followed the rest of the thread and I don't know why it was necessary to specify the metadata specifically in the first place. Simon -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop r

Re: [sqlalchemy] SQL expression for function (and/or method) dispatching?

2016-09-16 Thread Simon King
n querying, and you potentially need to aggregate multiple columns, I would have thought that what you really need is a plain python property, which does the string->value conversion in the getter and the opposite in the setter. Simon -- You received this message because you are subscribed to the

Re: [sqlalchemy] SQL expression for function (and/or method) dispatching?

2016-09-16 Thread Simon King
from and saving to the database. Simon On Fri, Sep 16, 2016 at 9:53 AM, Jinghui Niu <niujing...@gmail.com> wrote: > If I store the as DateTime values and with a second column to indicate > whether it's a date or datetime, it would look like this for a Date: > col1: "2016-0

Re: [sqlalchemy] SQL expression for function (and/or method) dispatching?

2016-09-16 Thread Simon King
? Is there a reason why you can't store them as proper DateTime values (perhaps with a second column to indicate whether or not the time part is valid)? Simon On Fri, Sep 16, 2016 at 4:39 AM, Jinghui Niu <niujing...@gmail.com> wrote: > I have the following code snippet, I marked my question in a com

Re: [sqlalchemy] Turning SAWarnings into exceptions

2016-09-15 Thread Simon King
(): "Convert SQLAlchemy warnings to exceptions" import sqlalchemy.exc warnings.simplefilter( 'error', sqlalchemy.exc.SAWarning ) Simon On Thu, Sep 15, 2016 at 3:09 PM, Simon King <si...@simonking.org.uk> wrote: > According to https://docs.python.org/2

Re: [sqlalchemy] Turning SAWarnings into exceptions

2016-09-15 Thread Simon King
According to https://docs.python.org/2/using/cmdline.html#cmdoption-W, the full form of -W (and PYTHONWARNINGS) is: action:message:category:module:line Empty fields are ignored, and unused trailing fields can be left out, so maybe "error::SAWarning" would work? Simon On Thu, Se

Re: [sqlalchemy] Session autoflush when using history_meta (examples/versioned_history)

2016-09-04 Thread Simon King
flush hook, check to see if the object has really changed (using the code from create_version). If it has, save it away in a set somewhere. 2. In a before_commit hook, iterate over that set and create the actual history entries. Simon -- You received this message because you are su

Re: [sqlalchemy] examples/versioned_history test_versioning.py doubts about TestVersioning.test_relationship

2016-09-02 Thread Simon King
By default, the session is flushed before any query, so that the query results are consistent with changes you may have made in-memory: http://docs.sqlalchemy.org/en/latest/orm/session_basics.html#flushing Hope that helps, Simon On Fri, Sep 2, 2016 at 5:12 PM, HP3 <henddher.pedr...@gmail.

Re: [sqlalchemy] setters and getters on an automapped table

2016-08-30 Thread Simon King
thon2.7/site-packages/sqlalchemy/util/_collections.py", > line 212, in __getattr__ > > raise AttributeError(key) > > AttributeError: hosts > > > On Fri, Aug 26, 2016 at 1:33 AM, Simon King <si...@simonking.org.uk> wrote: >> >> On Fri, Aug 26, 201

Re: [sqlalchemy] Wrong todo.id after the commit (a log string instead 1)

2016-08-26 Thread Simon King
“a.attribute” has to be evaluated and substituted into the string before the print statement can run. If you use the print *function* rather than the print *statement*, all the arguments will be evaluated before anything is displayed, so this also wouldn’t happen. Hope that helps, Simon --

Re: [sqlalchemy] setters and getters on an automapped table

2016-08-26 Thread Simon King
def mac_address(self, value): self._mac_address = encode_mac_address(value) If you want to be able to query using the decoded values, you could also try hybrid properties. Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups "sqlalche

Re: [sqlalchemy] hybrid_property vs. hybrid_method, other than the latter can take arguments?

2016-08-24 Thread Simon King
val).filter(Interval.length_property > 5) But the method would have to be used like this: session.query(Interval).filter(Interval.length_method() > 5) It's up to you which you prefer. Hope that helps, Simon -- You received this message because you are subscribed to the Google Group

Re: [sqlalchemy] Having SA generate constructor when using autoload.

2016-08-22 Thread Simon King
t__() > method is not automatically synthesized. > You'd probably be best off copying the SQLAlchemy code into your own project - it's not long: https://bitbucket.org/zzzeek/sqlalchemy/src/5145f671a4b5eb072e996bc450d2946d4be2a343/lib/sqlalchemy/ext/declarative/base.py?at=master=file-view

Re: [sqlalchemy] Tracking instance commit status

2016-08-11 Thread Simon King
understand the question here - it's not clear to me why get_or_create for the container objects is any different than get_or_create for any other object, or what that has to do with flushed-but-not-committed records. Why do you need to treat objects that have been flushed but not committed any differen

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

2016-08-02 Thread Simon King
/sqlalchemy/src/3873d7db340835a38e6b191e8466fb42c3a9d3f6/lib/sqlalchemy/engine/base.py?at=master=file-view-default#base.py-1235 Hope that helps, Simon On Tue, Aug 2, 2016 at 4:11 AM, Nikhil S Menon <nikhilsme...@gmail.com> wrote: > If the datatype of in database is Varchar its working fi

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

2016-07-29 Thread Simon King
class colname = 'some_column' column = getattr(Table, colname) session.query(Table).filter(column == value) # If Table is an instance of sqlalchemy.Table colname = 'some_column' column = Table.c[colname] session.query(Table).filter(column == value) Hope that helps, Simon -- You received th

Re: [sqlalchemy] Re: Execute with raw string not persisted to database

2016-07-25 Thread Simon King
Even when using the ORM you ought to be using session.commit() to commit transactions. If you've been using the ORM against MyISAM tables you can probably get away without it since MyISAM tables don't support transactions. Simon On Mon, Jul 25, 2016 at 1:31 PM, Rogier Eggers <rogier

Re: [sqlalchemy] Re: Execute with raw string not persisted to database

2016-07-25 Thread Simon King
...and the reason that it works on the older tables is probably that they use the MyISAM engine rather than InnoDB. On Mon, Jul 25, 2016 at 12:05 PM, Mehdi gmira wrote: > Maybe you forgot to commit ? > > > Le lundi 25 juillet 2016 12:08:17 UTC+2, Rogier Eggers a écrit : >> >>

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

2016-07-22 Thread Simon King
setLevel(logging.DEBUG) > > There is no code which change behavior (by filter) of SAWarning to 'error' > ... The python warnings system is completely separate from the logging system. Whether or not a particular warning is turned into an exception is driven by the "warnings filter"

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

2016-07-21 Thread Simon King
On Thu, Jul 21, 2016 at 5:58 PM, Jonathan Vanasco <jvana...@gmail.com> wrote: > > > On Thursday, July 21, 2016 at 12:15:40 PM UTC-4, Simon King wrote: >> >> There are some hints for keeping references to objects at: >> >> >> http://docs.sqlalchemy.or

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

2016-07-21 Thread Simon King
There are some hints for keeping references to objects at: http://docs.sqlalchemy.org/en/latest/orm/session_state_management.html#session-referencing-behavior Simon On Thu, Jul 21, 2016 at 5:11 PM, Mehdi gmira <mgm...@wiremind.fr> wrote: > Yeah I thought of that. I find it awkward be

Re: [sqlalchemy] explicitly add objects to identity map

2016-07-21 Thread Simon King
he question - objects loaded by session.query are *already* in the identity map for that session. If you have an object that wasn't loaded from the session originally, I think the official answer is session.merge(), although that returns a new object. Would that work in your instance? Simon -- You

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

2016-07-21 Thread Simon King
hat's a different > discussion. FWIW, I find alembic's autogeneration feature very handy here. I edit the Python class definitions then alembic inspects the database and generates an appropriate migration script: http://alembic.zzzcomputing.com/en/latest/autogenerate.html Hope that helps, Simon -- You r

Re: [sqlalchemy] Re: Specify query_cls for the one query

2016-07-13 Thread Simon King
/en/latest/_modules/examples/sharding/attribute_shard.html In the example, the query_chooser function is inspecting the query to see which backend database the query should be issued against, which I guess is what your "_analyze_base_query" method does. Would this work for you? Simo

Re: [sqlalchemy] Re: Specify query_cls for the one query

2016-07-12 Thread Simon King
Could you describe what you are trying to achieve? There's nothing about Mike's suggestion that means you need to create a new session - you can reuse any existing session. What does your CustomQueryCls do? Perhaps there's another way of doing what you want? Simon On Tue, Jul 12, 2016 at 11:09

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

2016-05-11 Thread Simon King
On Wed, May 11, 2016 at 10:37 AM, Piotr Dobrogost <p...@2016.groups.google.dobrogost.net> wrote: >> On Wednesday, May 11, 2016 at 11:03:57 AM UTC+2, Simon King wrote: >>> On Wed, May 11, 2016 at 9:39 AM, Piotr Dobrogost >>> >>> What's the reaso

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

2016-05-11 Thread Simon King
column which > begins with underscore (_acl) but the mock one does not. Oracle treats > unquoted version as invalid giving the following error: > ORA-00911: invalid character > > > What's the reason for these differences? > At least for the quoting issue, it sounds like you a

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

2016-05-10 Thread Simon King
le to filter all log messages generated by > SA by type of SQL (DDL in this case)? > Could you use Alembic's offline mode? http://alembic.readthedocs.io/en/latest/offline.html Simon -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsu

Re: [sqlalchemy] Trying to create string array columns with Alembic gives "NameError: name 'String' is not defined"

2016-04-26 Thread Simon King
run_migrations(**kw) > File "/var/www/ > www.example.org/venv3.4.2/lib/python3.4/site-packages/alembic/runtime/migration.py", > line 312, in run_migrations > step.migration_fn(**kw) > File "/var/www/ > www.example.org/src/crowdwave/alembic/versions/dd9e391f807

Re: [sqlalchemy] Generic mixin classes and relationship

2016-04-24 Thread Simon King
emy where, if you define a column as a foreign key, and you don’t give it an explicit type, it will use the same type as the referenced column. As for alternative approaches, perhaps some of the “Generic Associations” examples might give you some ideas: http://docs.sqlalchemy.org/en/latest/orm/ex

Re: [sqlalchemy] update instance.relation.attr in instance.attr "set event listener"

2016-03-29 Thread Simon King
://docs.sqlalchemy.org/en/rel_1_0/orm/session_events.html#session-persistence-mapper Simon On Wed, Mar 23, 2016 at 8:52 PM, sector119 <sector...@gmail.com> wrote: > Going back to the subject )) > > I get error (and no data updated) while using no_autoflush > > /Users/sector119/PythonV

Re: [sqlalchemy] Too slow commit?

2016-03-22 Thread Simon King
It sounds like the transaction for task B is starting before A's transaction has been committed, but you haven't really given enough information to debug further. How are you managing your sessions and transactions? Do B and A actually overlap (ie. does B start before A finishes)? Simon On Tue

Re: [sqlalchemy] Re: order by child object's field

2016-03-22 Thread Simon King
For what it's worth, SQLAlchemy usually does add the join condition for you, based on your relationship definitions. But the second parameter to query.join() is an optional expression that *replaces* the join condition that would normally be generated. Simon On Mon, Mar 21, 2016 at 5:42 PM

Re: [sqlalchemy] Re: order by child object's field

2016-03-21 Thread Simon King
ot;, > "Person"."LastName" > > But result doesn't looks like that it is secondary sorted by first > persons lastname. See as an example one "Periodical._name" (Bmc > Geriatrics) and the first persons lastname of 8 References. > > Bmc Geria

Re: [sqlalchemy] Modeling single FK to multiple tables

2016-03-21 Thread Simon King
tables. Simon On Mon, Mar 21, 2016 at 3:12 PM, Alex Hall <ah...@autodist.com> wrote: > Wow, thanks guys, especially for the sample code! I'm trying to use > the example (and fully understand it at the same time) but am running > into an error. This is the same error that made me look fo

Re: [sqlalchemy] Re: order by child object's field

2016-03-21 Thread Simon King
s index > field? As you can see in my first post this column doesn't have a > "name" (in pythonic meaning). It is just a Column("Index", ...). > ReferenceAuthor is an instance of sqlalchemy.Table, so you can refer to its columns as ReferenceAuthor.c.Index. Simon -- You receive

Re: [sqlalchemy] how can I search rows containing jsonb data on the basis of it's key>

2016-03-19 Thread Simon King
On Fri, Mar 18, 2016 at 5:12 AM, Krishnakant <krm...@openmailbox.org> wrote: > > > On Thursday 17 March 2016 03:46 PM, Simon King wrote: > > On Thu, Mar 17, 2016 at 7:19 AM, Krishnakant <krm...@openmailbox.org> > wrote: > >> Hello, >> I wish to search

Re: [sqlalchemy] how can I search rows containing jsonb data on the basis of it's key>

2016-03-19 Thread Simon King
@> '{"accountcode": 1}'::jsonb Another would be the ->> operator: select * from yourtable where dramt ->> 'accountcode' = '1' or cramt ->> 'accountcode' = '1' In SQLAlchemy, I think these would be expressed as: YourTable.dramt.contains({'accountcode': '1

Re: [sqlalchemy] Modeling single FK to multiple tables

2016-03-19 Thread Simon King
('vendor'), (saorm .joinedload('assignments') .joinedload('attachment') .joinedload('text')), ) item = q.first() print item print item.vendor for assignment in item.assignments: print assignment.attachment.att_data

Re: [sqlalchemy] OperationalError with SQLite with simple update query

2016-03-19 Thread Simon King
On Wed, Mar 16, 2016 at 3:23 PM, Piotr Dobrogost < p...@2016.groups.google.dobrogost.net> wrote: > On Wednesday, March 16, 2016 at 3:51:16 PM UTC+1, Simon King wrote: >> >> On Wed, Mar 16, 2016 at 1:43 PM, Piotr Dobrogost < >> p...@2016.groups.google.dobrogost.net&g

Re: [sqlalchemy] alchemy expressionconfusion in insert statement having jsonb field

2016-03-16 Thread Simon King
/rel_1_0/core/tutorial.html#executing-multiple-statements you should be able to write something like this: con.execute(voucher.insert(), vid=1, vdate=somedate, Cr=somedict) Simon -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To

Re: [sqlalchemy] Search in result

2016-03-16 Thread Simon King
l()”, you’ve already loaded all the rows from the database into Python. “n” is just a Python list at this point. To load an object given its primary key you can use: v = session.query(xx).get(5) This checks the session first to see if the object has already been loaded. If it hasn’t, it will query th

Re: [sqlalchemy] I wish to know how I use table ALIAS in alchemy core

2016-03-03 Thread Simon King
On Thu, Mar 3, 2016 at 12:01 PM, Krishnakant <krm...@openmailbox.org> wrote: > > > On Thursday 25 February 2016 03:50 PM, Simon King wrote: > > On Thu, Feb 25, 2016 at 9:43 AM, Krishnakant <krm...@openmailbox.org> > wrote: > >> Hello, >> I have a que

Re: [sqlalchemy] Assertion error on deleting one end of many-to-many relation

2016-03-03 Thread Simon King
"Person.preferred_activities" relationship is one-to-many, and so the default behaviour when deleting the Person will be to set the foreign keys pointing to it to NULL. In this case that means setting PersonActivity.idperson to NULL, but this is impossible since that column is part o

Re: [sqlalchemy] replacing a filter attribute, or iterating over a booleanclauselist?

2016-03-02 Thread Simon King
Out of interest, how are you building your query, and why do you need to be able to change the values afterwards? Simon > On 2 Mar 2016, at 21:59, Brian Cherinka <havok2...@gmail.com> wrote: > > Thanks, Mike. This is excellent. That did the trick. That's much easier

Re: [sqlalchemy] need help with query

2016-03-02 Thread Simon King
I don't understand that error - you're asking it to join along predefined relationships, so it shouldn't need to search for foreign keys at query time. "Category.products" is a relationship set up as the backref of Product.categories. Here's a working example. I had to add the definition of the

Re: [sqlalchemy] need help with query

2016-03-01 Thread Simon King
http://docs.sqlalchemy.org/en/rel_1_0/orm/tutorial.html#querying-with-joins You want something like: DBSession.query(Category).join(‘products’, ‘brand’).filter(Brand.slug==brand_slug) Hope that helps, Simon > On 1 Mar 2016, at 20:11, sector119 <sector...@gmail.com> wrote: >

Re: [sqlalchemy] Date range query problem

2016-03-01 Thread Simon King
m/dd') (I may have the syntax wrong - I don't use Oracle) Simon -- 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 sqlalchemy+unsubscr...@googlegroups.co

Re: [sqlalchemy] Need help with update + select query

2016-02-25 Thread Simon King
or Notice that neither of the columns selected are labelled "servings", so when you try to access "s.c.servings" later, you get an AttributeError. Try moving the ".label('servings')" so that it applies to the result of coalesce(), not avg(). Simon -- You

Re: [sqlalchemy] update instance.relation.attr in instance.attr "set event listener"

2016-02-25 Thread Simon King
your underlying problem, which is that you are assigning an unexpected object to your "label" property. I guess FieldStorage comes from your web framework, and you need to extract the actual value from that before assigning it to your mapped object. Simon On Thu, Feb 25, 2016 at 1:24 PM,

Re: [sqlalchemy] Re: Can I make bulk update through association proxy?

2016-02-25 Thread Simon King
On Thu, Feb 25, 2016 at 12:01 PM, Piotr Dobrogost < p...@2016.groups.google.dobrogost.net> wrote: > On Thursday, February 25, 2016 at 11:10:36 AM UTC+1, Simon King wrote >> >> >> I can't think of a way you could do this with objects you've already >> loaded i

Re: [sqlalchemy] I wish to know how I use table ALIAS in alchemy core

2016-02-25 Thread Simon King
ForeignKey('t.groupcode')), ) subgroup = t.alias('subgroup') j = t.join(subgroup, subgroup.c.subgroupof == t.c.groupcode) print sa.select([t.c.groupcode, subgroup.c.groupcode]).select_from(j) Output: SELECT t.groupcode, subgroup.groupcode FROM t JOIN t AS subgroup ON subgroup.subgroupof = t.group

Re: [sqlalchemy] Re: Can I make bulk update through association proxy?

2016-02-25 Thread Simon King
sion.query(Text).all() >> texts???values???.update(...) >> > > Any hints? > > I can't think of a way you could do this with objects you've already loaded into memory. Perhaps you could use Query.update to issue the appropriate SQL directly to the database? http://docs.sqlal

Re: [sqlalchemy] Re: Question about the other property of backref

2016-02-25 Thread Simon King
r the creation of all "pending" backref attributes, I think you can call sqlalchemy.orm.configure_mappers: http://docs.sqlalchemy.org/en/rel_1_0/orm/mapping_api.html#sqlalchemy.orm.configure_mappers Normally this gets called automatically when you start querying the database, but in certain i

Re: [sqlalchemy] update instance.relation.attr in instance.attr "set event listener"

2016-02-25 Thread Simon King
appen even without the attribute listener when you called session.flush() or session.commit(). The attribute listener is just causing the flush to happen earlier presumably because "target.product" has not yet been loaded from the database. Simon -- You received this message because you are s

Re: [sqlalchemy] Re: column names with spaces with Declarative

2016-02-22 Thread Simon King
that helps, Simon On Mon, Feb 22, 2016 at 4:08 PM, Nana Okyere <oky...@gmail.com> wrote: > Update: I'm on the current version of sqlalchemy and using oracle 12c. > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy&quo

Re: [sqlalchemy] connected using pyodbc; how to hook that to SA?

2016-02-19 Thread Simon King
. Maybe you could hack around the problem by setting a "dbms_ver" attribute on the pyodbc connection that you are creating in your custom creator function. This is where it gets used: https://github.com/ibmdb/python-ibmdbsa/blob/master/ibm_db_sa/ibm_db_sa/base.py#L481 Simon On Fri, Feb 19, 20

Re: [sqlalchemy] connected using pyodbc; how to hook that to SA?

2016-02-19 Thread Simon King
> If I don't get that, it's because I used a name that complains about > there being no attribute dbms_ver or server.version, depending on the > string. > > They don't make it easy, do they? > > On 2/19/16, Simon King <si...@simonking.org.uk> wrote: > > URI prefixes

Re: [sqlalchemy] connected using pyodbc; how to hook that to SA?

2016-02-19 Thread Simon King
URI prefixes are defined in the setup.py for the ibm_db_sa package: https://github.com/ibmdb/python-ibmdbsa/blob/master/ibm_db_sa/setup.py I would guess that you want to end up with the DB2Dialect_pyodbc class, which means you should use db2.pyodbc:// or ibm_db_sa.pyodbc:// Simon On Fri, Feb

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