[sqlalchemy] simple: get max id in table

2018-04-24 Thread Steve Murphy
I'm just not getting it: Want: select max(id) from table; attempt (latest): from sqlalchemy import * from sqlalchemy.engine import reflection from sqlalchemy import schema from sqlalchemy import exc from psycopg2 import * import re import time import os targethost = "192.168.181.204" targetdb

Re: [sqlalchemy] Tips for schema based db traversal and building

2015-09-30 Thread Steve Murphy
On Wednesday, September 30, 2015 at 1:43:46 PM UTC-6, Michael Bayer wrote: > > there's no known bugs in fetching unique constraints. PG 8.4 is a pretty > old version but should be working. > > note that a unique index and a unique constraint aren't listed as the same > thing, however.you m

Re: [sqlalchemy] Tips for schema based db traversal and building

2015-09-30 Thread Steve Murphy
See below On Tuesday, September 8, 2015 at 9:00:12 PM UTC-4, Michael Bayer wrote: > > > > you can get these like this: > > from sqlalchemy import inspect > insp = inspect(my_engine) > > fk_constraints = insp.get_foreign_keys('mytable') > uq_constraints = insp.get_unique_constraints('mytable') >

Re: [sqlalchemy] Tips for schema based db traversal and building

2015-09-09 Thread Steve Murphy
Oh, Michael! You have made my day. It just gets better and better! I don't know how I missed these items, but your examples are very helpful. Many thanks! On Tuesday, September 8, 2015 at 7:00:12 PM UTC-6, Michael Bayer wrote: > > > > On 9/8/15 12:57 PM, Steve Murphy w

[sqlalchemy] Tips for schema based db traversal and building

2015-09-08 Thread Steve Murphy
This message concerns using sqlAlchemy for schema based traversal and manipulation. It is the result of a project to transfer data from on database to another, where objects refer to each other, and must be copied to new rows in the target db, and have all the foreign references updated in the

Re: [sqlalchemy] Why is an association object mark as "dirty" instead of "deleted" when removed?

2015-05-06 Thread steve
Hmm, I don't think I could listen to the attribute event; it's saying that the AssociationProxy doesn't have "dispatch". Also, suppose I could detect the orphan-deletes earlier, what's the best way to suppress the objects marked as dirty? Here's my version of your code if it helps: https://gi

Re: [sqlalchemy] Why is an association object mark as "dirty" instead of "deleted" when removed?

2015-04-29 Thread steve
Since my association object doesn't have extra columns, the row ('bob, 'apple') will be deleted. However, if there are extra columns, then having it marked as "dirty" is desired. Perhaps I would delay my recording of my audit rows until after orphans are resolved. I am already using "after_flus

[sqlalchemy] Why is an association object mark as "dirty" instead of "deleted" when removed?

2015-04-28 Thread steve
bob.keywords.remove(apple) <== this is when my question is about sess.commit() When we remove the keyword, it marks the UserKeyword association object is "dirty" instead of "deleted". Why is that? Since the row is being removed, I would expect it to

Re: [sqlalchemy] Re: How to stop SQLAlchemy from adding an ON UPDATE clause to a TIMESTAMP column by default

2014-01-10 Thread Steve Johnson
My solution, since sqlalchemy seems to be ignoring the nullable and default kwargs, is this: time = Column( TIMESTAMP(), primary_key=True, server_default=text("'-00-00 00:00:00'")) The default is just never used. On Friday, January 10, 2014 12:2

Re: [sqlalchemy] Re: How to stop SQLAlchemy from adding an ON UPDATE clause to a TIMESTAMP column by default

2014-01-10 Thread Steve Johnson
I realize this thread is ancient, but I'm resurrecting it for Googleable posterity since I just ran across the same issue. The problem is that MySQL "helpfully" inserts the ON UPDATE cheese unless you specify a default and/or a NULL/NOT NULL value in the CREATE TABLE query. http://dev.mysql.co

Re: [sqlalchemy] Getting comparison TypeError when trying to commit "aware" datetime when previous value was "naive" datetime

2012-05-13 Thread Steve Zatz
> you should only be dealing with timezone-naive datetimes within a Python application Thanks - make sense although the klugey way around the problem is just to commit None before you change between naive and aware since comparisons with None are fine. -- You received this message because you are

[sqlalchemy] Getting comparison TypeError when trying to commit "aware" datetime when previous value was "naive" datetime

2012-05-12 Thread Steve Zatz
When I try to commit a timezone aware datetime to replace a value that was previously timezone naive, I get a TypeError when I try to do the commit with the message: TypeError: can't compare offset-naive and offset-aware datetimes Now I am not trying to compare anything but just store the new val

[sqlalchemy] Re: Joining three tables - Selecting column from two different tables

2011-01-20 Thread Steve
Hi, Thanks. Worked like a charm. Also thanks for SqlAlchemy. A refreshing change for someone from java background. I am using this with Jython. Thanks for the Jython support also. Steve On Jan 18, 8:54 pm, Michael Bayer wrote: > On Jan 18, 2011, at 9:11 AM, Steve wrote: > > >

[sqlalchemy] Joining three tables - Selecting column from two different tables

2011-01-18 Thread Steve
cessFactors.id).\ filter(ProbabilityModels.id == model_id).\ all() Thanks in advance. Steve. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe f

[sqlalchemy] Re: Determine what joins are in select statement

2009-11-01 Thread Steve Zatz
> compare join.left, join.right, join.onclause Thanks. That's what I needed. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To uns

[sqlalchemy] Re: Determine what joins are in select statement

2009-11-01 Thread Steve Zatz
compare(obj2) is False What is the best way to compare those two join objects and conclude they represent the same join? Steve --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to

[sqlalchemy] Re: Determine what joins are in select statement

2009-10-28 Thread Steve Zatz
> use query.statement to get at the SQL expression Thanks. That worked. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscri

[sqlalchemy] Re: Determine what joins are in select statement

2009-10-28 Thread Steve Zatz
is the second argument in visitors.traverse(). [It was missing in the most recent example but apparently an empty dictionary is fine.] Steve > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy&q

[sqlalchemy] Re: Determine what joins are in select statement

2009-10-28 Thread Steve Zatz
same join again)? Steve --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send emai

[sqlalchemy] Re: many-to-one question on delete

2009-09-14 Thread Steve Zatz
so I just need to work around that. Again, thanks for the help. Steve --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To

[sqlalchemy] many-to-one question on delete

2009-09-14 Thread Steve Zatz
to a context_id = 0. Thanks for any advice. Steve --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from

[sqlalchemy] Re: "LIKE" filter and psycopg2

2008-11-12 Thread Steve Howe
that confused me. It's working now, thanks, I needed the "ILIKE" function. -- Best Regards, Steve Howe --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this

[sqlalchemy] "LIKE" filter and psycopg2

2008-11-12 Thread Steve Howe
te cursor.execute(statement, parameters) TypeError: 'dict' object is unindexable I'm stuck. What should I be doing ? Use another syntax ? Replace psycopg2's paramstyle to non-escaping mode ? My environment: Python 2.5.2 SQLAlchemy 0.5.0.rc3 PostgreSQL 8.30 psycopg 2.0.7

[sqlalchemy] Re: adding a child to 2 parents, 2 ways

2008-10-22 Thread Steve Harris
Thanks for the explanation, Michael. The behavior is very sensible now that I see what's happening. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchem

[sqlalchemy] adding a child to 2 parents, 2 ways

2008-10-22 Thread Steve Harris
do want to thank zzzeek who very quickly provided workarounds in the trac entry. Thoughts? Is this the way it should be? -Steve --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to

[sqlalchemy] Re: trunk is now on 0.5

2008-05-10 Thread Steve Zatz
> be sure to clean out the .pyc files. That worked. Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from th

[sqlalchemy] Re: trunk is now on 0.5

2008-05-10 Thread Steve Zatz
Trunk Rev 4726 Note the following: Python 2.5.2 (r252:60911, May 7 2008, 15:19:09) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from sqlalchemy import * Traceback (most recent call last): File "", line 1, in File "

[sqlalchemy] Re: Mapper issue with r4485

2008-04-11 Thread Steve Zatz
> my hat's off to you for coming up with that relation(), it works again > in rev 4486. Ah the irony ... check out http://tinyurl.com/6kqv94 And thanks as always for your remarkable responsiveness and for sqlalchemy. It is indispensi

[sqlalchemy] Mapper issue with r4485

2008-04-10 Thread Steve Zatz
n are foreign. I am not sure what needs modification in the mapper to be compatible with the current trunk. Steve --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email

[sqlalchemy] Re: session.refresh

2008-03-06 Thread Steve Zatz
I am on current svn and have not tested expire but refresh is happy to refresh an object that is not in the session. Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> item = session.que

[sqlalchemy] session.refresh

2008-03-06 Thread Steve Zatz
This is probably obvious but I was confused by the fact that you can refresh an object through session.refresh(obj) but that doesn't guarantee that the object is in the session and doesn't put it in the session if it is not. Is the accepted way to handle this to just follow the refresh with a ses

[sqlalchemy] Re: self-referential table question

2008-01-28 Thread Steve Zatz
> another option is: > .query(Node).filter(not_(Node.id.in_(select([Node.parent_id] jason, thanks for the alternative method. Steve --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" g

[sqlalchemy] Re: self-referential table question

2008-01-28 Thread Steve Zatz
Michael, Works perfectly. Thanks much. Steve --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from

[sqlalchemy] self-referential table question

2008-01-27 Thread Steve Zatz
t the right query is. Any help would be appreciated. Steve --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe

[sqlalchemy] create indexes on function

2007-04-16 Thread Steve Huffman
Is it possible to create indexes using a function using sqlalchemy and postgresql? Something like: create index idx on table (lower(table.field)) Thanks, Steve --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups

[sqlalchemy] Re: Issue using rev 2425

2007-03-20 Thread Steve Zatz
Michael, thanks for working through this and for taking the time to explain what's going on and to provide alternative ways to getting this done. Your efforts to support the users of sqlalchemy are really extraordinary. --~--~-~--~~~---~--~~ You received this mess

[sqlalchemy] Re: Issue using rev 2425

2007-03-19 Thread Steve Zatz
Here you go. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For mor

[sqlalchemy] Re: Issue using rev 2425

2007-03-18 Thread Steve Zatz
2429 still has the problem. Below are the relevant tables and classes: item_table = Table('item',metadata, Column('id', Integer, primary_key=True), Column('uuid', String(32), unique=True, nullable=False), Column('parent_uuid', String(32), ForeignKey('ite

[sqlalchemy] Re: server_side_cursors

2007-03-18 Thread Steve Huffman
erwise. also the > databases will often not give you back the same column name as what > you gave it (case conventions, etc) and in some cases we dont even > have a column name to start with (like "select some_function()"). > > On Mar 17, 2007, at 8:41 PM, Steve Huffman wro

[sqlalchemy] Issue using rev 2425

2007-03-18 Thread Steve Zatz
I hadn't updated in several weeks so I am not sure when this issue first arose but with the following setup: mapper(Section, section_table, properties = {'items': relation(Item, backref='section'), 'keywords':relation(Keyword, primaryjoin=and_(keyword_table.c.uuid==it

[sqlalchemy] Re: server_side_cursors

2007-03-17 Thread Steve Huffman
then my reply you're about to read is probably out-of-context. On 3/17/07, Michael Bayer <[EMAIL PROTECTED]> wrote: > > sorry, i meant "cursor.description", not "cursor.metadata". > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscrib

[sqlalchemy] Re: server_side_cursors

2007-03-17 Thread Steve Huffman
s a > psycopg2 version issue, then everyone can just upgrade. which version are you using? > > On Mar 17, 2007, at 8:41 PM, Steve Huffman wrote: > > > > > I may be missing something fundamental here, but why doesn't it > > already know the metadat

[sqlalchemy] Re: server_side_cursors

2007-03-17 Thread Steve Huffman
I may be missing something fundamental here, but why doesn't it already know the metadata since I defined the columns in which I'm interested? thing_table = sa.Table("thing", md, sa.Column('id', sa.Integer, primary_key = True)) On 3/17/07, Michael Bayer <[EMAIL PROTECTED]> wrote: > > the cursor

[sqlalchemy] Updating an object by passing a dictionary?

2007-02-10 Thread Steve Bergman
ve to set each attribute separately. Thanks, Steve Bergman --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe

[sqlalchemy] Re: self-referential table question

2006-12-02 Thread Steve Zatz
Works. Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For

[sqlalchemy] Re: self-referential table question

2006-12-02 Thread Steve Zatz
Oops, I may have spoken too soon about things working... The children relationship works fine and generates the correct query. However, I don't think that the parent backref relationship is generating the right query. item0.parent produces the following where clause: ... WHERE ? = item.parent_

[sqlalchemy] Re: self-referential table question

2006-12-02 Thread Steve Zatz
Works perfectly. Your responsiveness and the usefulness of SQLAlchemy continue to amaze. Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@g

[sqlalchemy] self-referential table question

2006-12-01 Thread Steve Zatz
The table is the following: item_table = Table('item', metadata, Column('id', Integer, primary_key=True), Column('uuid', String(32), unique=True, nullable=False), Column('parent_uuid', String(32), ForeignKey('item.uuid'), nullable=True), ... With mapper: mapper(Item, item_table, pro

[sqlalchemy] Re: AssociationProxy change in 2091

2006-11-10 Thread Steve Zatz
I guess that should really be: order.items.append((item('SA T-Shirt'), {'price':2.99})) which looks awkward enough that I am happy to drop the point. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" g

[sqlalchemy] AssociationProxy change in 2091

2006-11-10 Thread Steve Zatz
I am probably the last person to comment on aesthetics but shouldn't the syntax be: order.items.append((item('SA T-Shirt'), price=2.99) ) to at least preserve Python-like list append syntax instead of: order.items.append(item('SA T-Shirt'), price=2.99) which admittedly looks simpler but is not

[sqlalchemy] Problem with count in rev 2089

2006-11-09 Thread Steve Zatz
Prior to 2089, the following worked fine: session.query(ItemKeyword).count() where ItemKeyword has a compound primary key that is defined in its mapper as follows: mapper(ItemKeyword, itemkeyword_table, primary_key = [itemkeyword_table.c.item_uuid, itemkeyword_table.c.keyword_uuid], properties=

[sqlalchemy] Re: Using order_by in an association many-to-many relationship with columns from the association object

2006-10-31 Thread Steve Zatz
The diffs are a little hard when you're not sure where the line breaks are (and the cascade all appears to be on the wrong line to me) but just for my own sanity, you're saying that: mapper(Item, items, properties={'keywords':relation(KeywordAssociation, cascade="all,delete-orphan")}) is equival

[sqlalchemy] Problem with Boolean defaults

2006-10-28 Thread Steve Zatz
Current trunk. sqlite Simple example below in which a Boolean with default = True is being created with default of 0. The other defaults in the example below work fine. item_table = Table('item',metadata, Column('id', Integer, primary_key=True), Column('name',String

[sqlalchemy] Re: Problem with mapper relationship when lazy=False

2006-10-23 Thread Steve Zatz
> the eager load should be able to go through the association object > down to the endpoint Keyword objects Thanks -- that does work. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to th

[sqlalchemy] Re: Problem with mapper relationship when lazy=False

2006-10-23 Thread Steve Zatz
> youre really looking to have an association object pattern here. I thought you might recommend that. My problem last time I tried an association object was that in the following situation: item table keyword table itemkeyword table (and association object) I couldn't get the keywords to eager

[sqlalchemy] Problem with mapper relationship when lazy=False

2006-10-23 Thread Steve Zatz
Briefly, I have a situation in which a mapper works fine unless I change loading to lazy=False on one of the relationships. The mapper is: mapper(Item, item_table, properties = dict(keywords = relation(Keyword, secondary=itemkeyword_table, lazy=False, backref='items'), display_keywords = relatio

[sqlalchemy] Re: Association Object Question

2006-10-16 Thread Steve Zatz
> you could also do it just with custom properties on your class ... Thanks -- that is a pretty simple way to do it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send em

[sqlalchemy] Association Object Question

2006-10-16 Thread Steve Zatz
My question is about using Association Objects. While they certainly make some things more natural, it seems that there is a price to pay for not being able to do: an_items_keywords = item.keywords but to instead have to write an_items_keywords = [ik.keyword for ik in item.itemkeywords] which