Re: [sqlalchemy] SQLSoup, whitespace

2013-11-16 Thread Simon King
On 16 Nov 2013, at 00:23, Tim Pierson tim.pier...@gmail.com wrote:

 Happy Friday night everyone.
 
 Maybe there's an easy way to deal with this:
 How can I use the SQLSoup insert function to update columns whose names 
 contain whitespace?
 
 ie:  db.table.insert(XML Schema Version=None)
 
 Are there any cool tricks I don't know?
 Thanks
 

How about:

  values = {‘XML Schema Version’: None}
  db.table.insert(**values)

Hope that helps,

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.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [sqlalchemy] SQLSoup, whitespace

2013-11-16 Thread Tim Pierson
Ahh! yes ! I tried that but in my fatigue I got the syntax wrong. Thanks!

Sent from my iPad

 On Nov 16, 2013, at 2:35 PM, Simon King si...@simonking.org.uk wrote:
 
 On 16 Nov 2013, at 00:23, Tim Pierson tim.pier...@gmail.com wrote:
 
 Happy Friday night everyone.
 
 Maybe there's an easy way to deal with this:
 How can I use the SQLSoup insert function to update columns whose names 
 contain whitespace?
 
 ie:  db.table.insert(XML Schema Version=None)
 
 Are there any cool tricks I don't know?
 Thanks
 
 
 How about:
 
  values = {‘XML Schema Version’: None}
  db.table.insert(**values)
 
 Hope that helps,
 
 Simon
 
 -- 
 You received this message because you are subscribed to a topic in the Google 
 Groups sqlalchemy group.
 To unsubscribe from this topic, visit 
 https://groups.google.com/d/topic/sqlalchemy/I6-C__9ZNYk/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to 
 sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/groups/opt_out.

-- 
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.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [sqlalchemy] Using PostgreSQL DELETE ... USING tableA... syntax

2013-11-16 Thread Jon Nelson
That's pretty spectacular!
Will something like that make it into a future release of SQLAlchemy?


--
Jon

-- 
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.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


[sqlalchemy] declarative, reflection, and secondary tables.

2013-11-16 Thread Jon Nelson
I've been experiencing a weirdness.

Using SQLAlchemy 0.8.3 and PostgreSQL with declarative (and deferred
reflection), if I don't manually force a reflection *before* I call
prepare then - when I use certain objects - I get an error which
indicates that SQLAlchemy did not reflect secondary tables. Is this a
known issue? It's really hard to find an isolated test case.


InvalidRequestError: When initializing mapper
Mapper|ObjectOne|table_one, expression 'table_one_secondary_table'
failed to locate a name (name 'table_one_secondary_table' is not
defined). If this is a class name, consider adding this
relationship() to the class 'ObjectOne class after both dependent
classes have been defined.


the table 'table_one_secondary_table' is like this:

class ObjectOne(Base):
  __tablename__ = 'table_one'
  
  object_twos = relationship(
ObjectTwo, backref='object_one',
cascade=save-update,merge,refresh-expire,expunge,
secondary='table_one_secondary_table',
passive_deletes=True
  )

-- 
Jon
Software Blacksmith

-- 
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.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [sqlalchemy] Using PostgreSQL DELETE ... USING tableA... syntax

2013-11-16 Thread Michael Bayer
someday sure :)

a lot of times I get pull requests for small things like this, the approach 
would be built into a combination of sql/compiler.py and postgresql/base.py.   
though some kind of approach that meets this and MySQL’s somewhat different 
form should be worked out ahead of time.


On Nov 16, 2013, at 3:59 PM, Jon Nelson jnel...@jamponi.net wrote:

 That's pretty spectacular!
 Will something like that make it into a future release of SQLAlchemy?
 
 
 --
 Jon
 
 -- 
 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.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/groups/opt_out.



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [sqlalchemy] declarative, reflection, and secondary tables.

2013-11-16 Thread Michael Bayer

On Nov 16, 2013, at 4:08 PM, Jon Nelson jnel...@jamponi.net wrote:

 I've been experiencing a weirdness.
 
 Using SQLAlchemy 0.8.3 and PostgreSQL with declarative (and deferred
 reflection), if I don't manually force a reflection *before* I call
 prepare then - when I use certain objects - I get an error which
 indicates that SQLAlchemy did not reflect secondary tables. Is this a
 known issue? It's really hard to find an isolated test case.


that actually sounds like a real issue / missing feature since I’m not 
recalling prepare() is going to hit the “secondary” tables also.   

it should be easy to reproduce….(let’s see)….sure, simple.  this includes a 
workaround.  a new ticket with a patch is at 
http://www.sqlalchemy.org/trac/ticket/2865

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base, DeferredReflection


Base = declarative_base(cls=DeferredReflection)

class A(Base):
__tablename__ = 'a'
bs = relationship(B, secondary=atob)

class B(Base):
__tablename__ = 'b'


e = create_engine(sqlite://, echo=True)
e.execute(
create table a(id integer primary key)
)
e.execute(
create table b(id integer primary key)
)
e.execute(
create table atob(
a_id integer references a(id),
b_id integer references b(id),
primary key (a_id, b_id)
)
)

Base.prepare(e)

# if this isn't done, failure
#Table('atob', Base.metadata, autoload=True, autoload_with=e)

print A.bs.__clause_element__()

 
 
 InvalidRequestError: When initializing mapper
 Mapper|ObjectOne|table_one, expression 'table_one_secondary_table'
 failed to locate a name (name 'table_one_secondary_table' is not
 defined). If this is a class name, consider adding this
 relationship() to the class 'ObjectOne class after both dependent
 classes have been defined.
 
 
 the table 'table_one_secondary_table' is like this:
 
 class ObjectOne(Base):
  __tablename__ = 'table_one'
  
  object_twos = relationship(
ObjectTwo, backref='object_one',
cascade=save-update,merge,refresh-expire,expunge,
secondary='table_one_secondary_table',
passive_deletes=True
  )
 
 -- 
 Jon
 Software Blacksmith
 
 -- 
 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.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/groups/opt_out.



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [sqlalchemy] using Column.in_(a_large_list) is very slow.

2013-11-16 Thread Jonathan Vanasco
Well the queries are totally different...

 SELECT * FROM test WHERE id IN (SELECT test.id FROM test LIMIT 10) 

That's 100% in your database, and a single executable.

 SELECT * FROM test WHERE id IN ( 1...10 ) 

You have SQL Alchemy generating that query  all the bind params, then 
transmitting it to the DB, then the DB doing it's own testing against the 
bind values (which could be different than in the first query, depending on 
the DB ).  

If you're on PostgreSQL , try both queries with an EXPLAIN ANALYZE ( 
ie, EXPLAIN ANALYZE SELECT )  I forget the MySQL and Oracle commands to 
profile.  You can also use SqlAlchemy events to time the query generation 
-- I posted a question within the past 3 weeks on this, and it has some 
sample code references from Mike Bayer in one of the responses.  The events 
will let you know how much time is spent on compiling the query and other 
tools.  IIRC, you still need to time the actual query in the DB .


-- 
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.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.