[sqlalchemy] How to query objects in a session

2012-09-25 Thread Eduardo
Hi,
I am trying to find some efficient way to query objects stored in the 
session.
Do I have to loop through the session to find all objects which names are 
John for example or there is some more efficient way to do this.
The filter() would be perfect but it is not applicable for the session 
objects.
Thanks,
ED

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/fBs961TS6z4J.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Using count and distinct with window function

2012-05-16 Thread Eduardo


Hello,
I have got a query of the following type:

rows = session.query(*[func.count().over().label(count)]+map(lambda column: 
MyClass.__dict__[columns],columns)).filter(...).limit(n).offset(m).all()

it returns the number of results together with values of selected columns. The 
problem is when I try to apply the distinct query I see that 
func.count().over().label(count) does not return correct results, that is, it 
returns the number of results for the query by which the distinct function is 
omitted.
Is there any workaround for this problem?
The query contains no joins.
Thank you
ED

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/s2PjnmdvWuwJ.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: Using count and distinct with window function

2012-05-16 Thread Eduardo
To put it more clear why:

rows = session.query(*[func.count().over().label(count)]+map(lambda column: 
MyClass.__dict__[columns],columns)).filter(...).limit(n).offset(m).all()
works and
*rows = session.query(*[func.count().*

*over().label(count)]+map(**lambda column: 
MyClass.__dict__[columns],**columns)).filter(...).distinct().limit(n)**.offset(m).all()*
does not?
Thanks





Am Mittwoch, 16. Mai 2012 12:07:26 UTC+2 schrieb Eduardo:

 Hello,
 I have got a query of the following type:

 rows = session.query(*[func.count().over().label(count)]+map(lambda column: 
 MyClass.__dict__[columns],columns)).filter(...).limit(n).offset(m).all()

 it returns the number of results together with values of selected columns. 
 The problem is when I try to apply the distinct query I see that 
 func.count().over().label(count) does not return correct results, that is, 
 it returns the number of results for the query by which the distinct function 
 is omitted.
 Is there any workaround for this problem?
 The query contains no joins.
 Thank you
 ED



-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/W80zRGtGptAJ.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: Using count and distinct with window function

2012-05-16 Thread Eduardo

Hi,
I am trying to write this SQL coomand:

SELECT DISTINCT(col1, col2,col3) FROM mytable WHERE col1='something' 

in sqlalchemy form:

columns=['col1','col2','col3']

*rows = session.query(*[func.count().over().label(count)]+map(lambda column: 
MyClass.__dict__[columns],columns))*.filter(...).limit(n).offset(m).all()

this query works it returns the results together with the number of hits.
The problem is that when I apply the distinct() command
*rows = session.query(*[func.count().over().label(count)]+map(lambda column: 
MyClass.__dict__[columns],columns))*.filter(...).limit(n).offset(m).*distict()*.all()
 *func.count().over().label(count) does not show the correct number of hits 
because func.count() relates to all column in table and to those selected - 
that is col1, col2 and col3
My question is how to write the count function that will correctly count number 
of distinct hits but only for the selected columns.*
I tried with:
 
*func.count().over(partition_by=MyClass.col1,MyClass.col2,MyClass.col3).label(count)*

*and it did not work

If I want to use:*

 
*func.count(distinct(MyClass.col1,MyClass.col2,MyClass.col3)).over().label(count)

only one column is allowed as the input argument for the count() function.


Is there any way to solve this?
Thanks* 



Am Mittwoch, 16. Mai 2012 12:07:26 UTC+2 schrieb Eduardo:

 Hello,
 I have got a query of the following type:

 rows = session.query(*[func.count().over().label(count)]+map(lambda column: 
 MyClass.__dict__[columns],columns)).filter(...).limit(n).offset(m).all()

 it returns the number of results together with values of selected columns. 
 The problem is when I try to apply the distinct query I see that 
 func.count().over().label(count) does not return correct results, that is, 
 it returns the number of results for the query by which the distinct function 
 is omitted.
 Is there any workaround for this problem?
 The query contains no joins.
 Thank you
 ED



-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/11I7cmn-UaoJ.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: Using count and distinct with window function

2012-05-16 Thread Eduardo


Am Mittwoch, 16. Mai 2012 12:07:26 UTC+2 schrieb Eduardo:

 Hello,
 I have got a query of the following type:

 rows = session.query(*[func.count().over().label(count)]+map(lambda column: 
 MyClass.__dict__[columns],columns)).filter(...).limit(n).offset(m).all()

 it returns the number of results together with values of selected columns. 
 The problem is when I try to apply the distinct query I see that 
 func.count().over().label(count) does not return correct results, that is, 
 it returns the number of results for the query by which the distinct function 
 is omitted.
 Is there any workaround for this problem?
 The query contains no joins.
 Thank you
 ED



-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/a2L969rnvmkJ.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Re: Using count and distinct with window function

2012-05-16 Thread Eduardo
*SORRY

I want to create query that will return as a first element the number of 
hits *

*SELECT COUNT(*) FROM(SELECT (DISTINCT(col1,col2,col3)) FROM mytable where 
col1='something**' LIMIT 1 OFFSET 2)

and in the second part should be values of the hits

 **SELECT (DISTINCT(col1,col2,col3)) FROM mytable where col1='something**' 
LIMIT 1 OFFSET 2*

*is it possible to solve this with one query I want to avoid having to 
apply first query.count() and then query.all() to get results is this 
possible to do this with one query.
thanks*
*

*

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/xr5fGu1B0yoJ.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Re: Using count and distinct with window function

2012-05-16 Thread Eduardo


Am Mittwoch, 16. Mai 2012 19:59:10 UTC+2 schrieb Michael Bayer:
If I put count() the result will be the number of hits I would like to have 
both the number of hits and resulting column values for example
[(33,val1,val2,val3),(33, val21,val22,val23),...]
If I execute it with 
Session().query(
mytable.c.col1, 
mytable.c.col2, 
mytable.c.col3).\
distinct().\
filter(mytable.c.col1=='something').\
limit(1).offset(2).\
count()
I get only [33] (for example)
if I use
from_self()
I get an error
 ProgrammingError: (ProgrammingError) column anon_1.col1 must appear in 
the GROUP BY clause or be used in an aggregate function

Thanks
 

 print Session().query(
 mytable.c.col1, 
 mytable.c.col2, 
 mytable.c.col3).\
 distinct().\
 filter(mytable.c.col1=='something').\
 limit(1).offset(2).\
 from_self(func.count('*'))

 or just say count() instead of from_self(), will execute it.   you don't 
 need distinct(col1, col2, col3) here, only DISTINCT col1, col2, col3, 
 since you aren't applying DISTINCT to a subset of the available columns. 
  DISTINCT(x, y, z) is a Postgresql-specific extension (see 
 http://www.postgresql.org/docs/9.0/static/sql-select.html#SQL-DISTINCT )




 On May 16, 2012, at 1:50 PM, Eduardo wrote:

 *SORRY

 I want to create query that will return as a first element the number of 
 hits *

 *SELECT COUNT(*) FROM(SELECT (DISTINCT(col1,col2,col3)) FROM mytable 
 where col1='something**' LIMIT 1 OFFSET 2)

 and in the second part should be values of the hits

  **SELECT (DISTINCT(col1,col2,col3)) FROM mytable where col1='something**' 
 LIMIT 1 OFFSET 2*

 *is it possible to solve this with one query I want to avoid having to 
 apply first query.count() and then query.all() to get results is this 
 possible to do this with one query.
 thanks*
 *

 *

 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To view this discussion on the web visit 
 https://groups.google.com/d/msg/sqlalchemy/-/xr5fGu1B0yoJ.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 To unsubscribe from this group, send email to 
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/sqlalchemy?hl=en.




-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/iXkaEJJFUi0J.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Removing duplicates

2012-05-08 Thread Eduardo
Hi,
Is there any function in sqlalchemy that filters out duplicates?
For example the following rows satisfy a query:
1. (john, 23 ,  lpgh )
2.(steve , 35 , dbr )
3. (john ,76, qwe)
4. (mark, 35, epz)
I would like that my query results contain only one row with john (either 1 
or 3 which one is not important) or with 35 (either 2 or 4).
I tried with distinct(col) but it could not do the work.
Thanks

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/xnt0Zo5tSPUJ.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Returningquery results with the result number

2012-03-15 Thread Eduardo
Hi,
In order to avoid bottlenecks I am force to limit the number of returned 
results using LIMIT and OFFSET.
Since I am not returning all results upon a query I need to include the 
number of hits in the result.
somequery.count()
somequery.limit(n).offset(m).all()
The problem is that response time takes twice as long as for either the 
count query or the query retrieving results.
Is there any way to do this more efficiently, to make a query first, then 
to count results and return the result chunk defined with LIMIT and OFFSET?
What is the best practice for this?
Thanks 
ED 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/XXZtDSStLO8J.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] modifying enable_seqscan option

2012-03-15 Thread Eduardo
Hi,
Is it possible to set this option to off by using sqlalchemy?
Thanks
Ed

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/JGkEvUVvoncJ.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] checking if some object with the given id is in a session

2011-09-19 Thread Eduardo
Hi,
I create a certain number of objects in a loop, I check if each of the
objects is already stored in the session and if it is not I add it to
the session.

session = Session()
for item in items:
   item1=create_item()
   if not item1 in session:
   session.add(item1)
session.commit()

The problem is that when I add two objects to the session that are not
the same but have some id I get the error:
get an error sqlalchemy.exc.IntegrityError: (IntegrityError) duplicate
key value violates unique constraint
Is there any function that directly checks if there two objects with
the same id in a session?
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] and_ and or_ combined in query

2011-09-15 Thread Eduardo
Hi,
The keys of the following dictionary are column names while values are
lists of options for the column in question:

colvsopt={'column1':['option1','option2'],'column2':
['option3','option4l'],.}

I need to write a query:
SELECT * FROM SOMETABLE WHERE (column1=option1 OR column1=option2) AND
(column2=option3 OR column2=option4) AND ...
in sqlalchemy. I tried almost everything but it did not work my best
try is:

query(tab).filter(and_(*(map(or_(*(map(lambda
cv:tab.columns[col]==cv,colvsopt[col]))for col in colvsopt.keys())

Here I get the error:
sqlalchemy.exc.ArgumentError: filter() argument must be of type
sqlalchemy.sql.ClauseElement or string

Could someone help me with this?
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] updating of the query results

2011-09-09 Thread Eduardo
Dear all,
I make a query to find the highest version of a document and then I
want to set a flag to column actual to 1 (TRUE) to all entries
satisfying the query. I dont want to loop through hits but to set this
flag in a one stroke with update. However I get this error:
sqlalchemy.exc.InvalidRequestError: Could not evaluate current
criteria in Python. Specify 'fetch' or False for the
synchronize_session parameter. (Related to the line with update
function!!). What is the problem or is there any alternative?
Thanks

metadata,session,engine=myf(confile)
mytab = Table(dbname, metadata, autoload=True)
class SomeTable(object):
pass
mapper(SomeTable,mytab).compile()
vquery=session.query(func.max(mytab.columns['version']),mytab.columns['id']).group_by(mytab.columns['id'])
endquery=session.query(mytab).filter(tuple_(mytab.columns['version'],mytab.columns['id']
 ).in_(vquery))
endquery.update({mytab.columns[actual]:1})
ses.commit()

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] killing idle processes

2011-09-02 Thread Eduardo
Hi,
I made simple query to a potgres DB:
___
engine=create_engine(path)
metadata=MetaData()
Session=sessionmaker(bind=engine)
session=Session()
session.execute('SELECT value FROM table)
.
.
session.close()
_

However execution of this code creates an idle process. How can I
prevent this?
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] ordering slices of the result

2011-09-02 Thread Eduardo
Hello,
I have a query which results (columns id,name) I need to order
alphabetically by name.
Then I need to take a slice of the results and to keep them ordered:


results=somequery.order_by(datab.columns['name'])
slices=results.slice(start,end)
res={}
for slice in slices:
  res[str(slice[0])]=str(slice[1])
for id in res.keys():
  print id, res[id]
_
the print line however does not show that id, name (res[id]) pairs
ordered alphabetically. Does anyone know why?
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: group_by argument as a result of a query

2011-08-15 Thread Eduardo
Here is the example:


column_names = session.query(tab.c.name).filter(tab.c.value==354)
column_names = [column_name for (column_name,) in column_names]
query=sess.query(func.max(tab.columns['name']),datab.columns['article_id']).group_by(*column_names).all()


I get an error here:
ProgrammingError: (ProgrammingError) syntax error at or near .6
LINE 2: ... GROUP BY fde.ck1.LKUT.RAT-ES.vertic.6hpa.low.6hdfjks.rih


On Aug 12, 7:14 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 can you please illustrate a simple SQL statement that illustrates what you 
 are trying to achieve ?  

 On Aug 12, 2011, at 1:00 PM, Eduardo wrote:

  Dear all,
  I am trying to limit group_by function only on the rows that satisfy
  certain query
  if I use group_by(table.c.something) this pertains to whole table.
  I tried to use elements of the tuple rendered as a result of a query
  as arguments (as it has been suggested on this forum) but it did not
  work.
  Is this possible at all?
  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 
  sqlalchemy+unsubscr...@googlegroups.com.
  For more options, visit this group 
  athttp://groups.google.com/group/sqlalchemy?hl=en.



-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: group_by argument as a result of a query

2011-08-15 Thread Eduardo
This I want to do:
1) I want to find all names that satisfy this query
column_names = session.query(tab.c.name).filter(tab.c.value==354)

2) Among those rows I want to find those with the highest id ( all
rows with the same name are fist grouped and only the one with the
highest id is retained the rest is discarded). Each of the names
satisfying the query 1 will be represented with one row having the
highest id:

column_names = [column_name for (column_name,) in column_names]

query=sess.query(func.max(tab.c.id),tab.c.name).group_by(*column_names).all()


Is there any better way to do this?
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] bulk selection

2011-08-12 Thread Eduardo
Dear All,
I have a list of elements for which I need to establish if they are in
a tadabase. I can make for each element a separate query but I am
afraid that that is not the best approach what is the best practice in
this case?
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] group_by argument as a result of a query

2011-08-12 Thread Eduardo
Dear all,
I am trying to limit group_by function only on the rows that satisfy
certain query
if I use group_by(table.c.something) this pertains to whole table.
I tried to use elements of the tuple rendered as a result of a query
as arguments (as it has been suggested on this forum) but it did not
work.
Is this possible at all?
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] The capacity of the session

2011-08-12 Thread Eduardo
Dear all,
How can I determine the number of objects (the memory capacity) that a
session can take? How can I determine the size of an object?
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: group_by by the result of some other query

2011-08-11 Thread Eduardo
Hi Thanks for the answer,
This is my query
column_names = session.query(tab.c.name).filter(tab.c.value==354)
column_names = [column_name for (column_name,) in column_names]
query=sess.query(func.max(tab.columns['name']),datab.columns['article_id']).group_by(*column_names).all()

I get an error here:

ProgrammingError: (ProgrammingError) syntax error at or near .6
LINE 2: ... GROUP BY fde.ck1.LKUT.RAT-ES.vertic.6hpa.low.6hdfjks.rih

What does this mean?
Thanks
^
 'SELECT max(sometable.name) AS max_1, sometable.id AS sometable_id
\nFROM sometable GROUP BY fde.ck1.LKUT.RAT-ES.vertic.6hpa.low.
6hdfjks.rihfjkdp1.fhsdjk00-1900.nhgtec,.

On Aug 11, 7:34 am, Andrew Taumoefolau zen...@gmail.com wrote:
 Hi Eduardo,

 group_by accepts strings, so this is certainly possible. You might do it like 
 so:

 # build our column names query

 # execute and a build a list of strings from our query

 # group the results of query1 by the list of column names we just created
 query1 = query1.group_by(*column_names)

 Cheers,

 Andrew Taumoefolau
 andrew.taumoefo...@gmail.com

 On 11/08/2011, at 2:43 AM, Eduardo wrote:

  Dear all,
  I am trying to find a way to limit group_by arguments of one query
  only to the values of some other query.
  Is this doable? If yes how to do that.
  This is an example how query looks like:
  query1.group_by(sesion.query(tab.columns['name']).filter(datab.columns['value']==354).all())
  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 
  sqlalchemy+unsubscr...@googlegroups.com.
  For more options, visit this group 
  athttp://groups.google.com/group/sqlalchemy?hl=en.



-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] group_by by the result of some other query

2011-08-10 Thread Eduardo
Dear all,
I am trying to find a way to limit group_by arguments of one query
only to the values of some other query.
Is this doable? If yes how to do that.
This is an example how query looks like:
query1.group_by(sesion.query(tab.columns['name']).filter(datab.columns['value']==354).all())
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] How to optimize the max group wise query

2011-08-04 Thread Eduardo
Dear all,
I have the following query that is made of 3 queries on only ONE
TABLE:

1. Step simple normal query

somequery=session.query(tab.columns['name'],tab.columns['id']).filter(tab.columns['value']==6)

2. Step: finding the max serial number for each serie

maxquery=session.query(func.max(tab.columns['serial_number']),datab.columns['serie']).group_by(datab.columns['serie'])

3. Step: find name and id of each row satisfying query from Step1
having maximal serial number in a serie
finalquery=somequery.filter(tuple_(tab.columns['serial_number'],datab.columns['serie']).in_(fidq))

Is there any more efficient way to do this? I am especially not
thrilled with the step 3 (creating tuples and then searching
equivalents from the results of the query 2). I think it is very cost-
intensive.

Remark: All rows with the same name and id also have the same serie
attribute.

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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Are data really in database using session.comit

2011-08-01 Thread Eduardo
Daer all

I have a following problem :

Session = sessionmaker(bind=engine)

session = Session()
for item in items:
item1 = session.query(item)
if len(item1)==0:
session.add(item1)
session.commit()

The session is valid for a loop and I write items in a database during
each iteration. Can it happen that if an item is identical to the
previous one, the session.commit() will not make it to write the
previous item in the database before the query of the next iteration
is executed and the next session.commit() will fail because of
sqlalchemy.exc.IntegrityError: (IntegrityError) duplicate key value
violates unique constraint.
How can I make sure that the previous item is already in the database
before the query in the next iteration is carried out?
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] intersecting query with different numbers of selectables

2011-07-28 Thread Eduardo
Dear all,
I have 2 queries:
1)
query1=session.query(func.max(datab.columns['counter']).label('t1')).group_by(datab.columns['site'])
query2=session.query(tab.columns['name'],tab.columns['id'],tab.columns['counter']).filter(datab.columns['visits']==15)

Now I would like to get all pairs
(tab.columns['name'],tab.columns['id']) having the counter attribute
that satisfy query1. I tried subqueries and joins but to no avail.
How to solve this?
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] writing a (sub)query

2011-07-27 Thread Eduardo
I have the following statement :

SELECT name, id, division, value,
FROM (
SELECT name, id, division,value, max(value) over
(partition by division) as max_val
 FROM tab1
  )
WHERE value = max_val

I try to turn this sql statement into a Query object
I tried this

sqlquery=session.query(sometab)

sqlquery.statement= SQL QUERY GIVEN ABOVE

but it does not work because statement cannot be set directly.
What is get-around for this?
Can this statement be written as a subquery? If yes, how? I saw
several example of subqueries on the internet but none of these seem
to be suitable for this statement.
Thanking in advance
Eddie

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: information about filed create_engine

2011-07-19 Thread Eduardo
/.../.../python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/
dialects/postgresql/psycopg2.py, line 234, in dbapi
 psycopg = __import__('psycopg2')
ImportError: No module named psycopg2

The module psycopg2 is  already installed in the site-packages
directory. I even included the path in the system variable by :
sys.path.append('/.../.../python2.6/site-packages/') in the wsgi
script.Still it won't work.
Why?


On Jul 18, 5:23 pm, King Simon-NFHD78
simon.k...@motorolasolutions.com wrote:
  -Original Message-
  From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com]
  On Behalf Of Eduardo
  Sent: 18 July 2011 15:54
  To: sqlalchemy
  Subject: [sqlalchemy] Re: information about filed create_engine

  Yes, I use wsgi server of the python library bottle and I don't have
  any problem but when I want to use the same script via the apache web
  server I get only a server error no exception could be caught not
  even
  by using the code snippet from you (Thanks by the way). I simply
  included many print lines that appear in the error log file. The
  create_engine fails (I know it from try and except) but I cannot
  catch
  any exception that sheds some light on the reason of the failure.

 If you are getting a generic server error from Apache, you'll normally
 find the reason in the Apache error log (the location depends on your
 installation, but typically it is something like
 /var/log/httpd/error_log. Does that shed any light on the problem?

 Simon

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: information about filed create_engine

2011-07-18 Thread Eduardo
I dont get any log. The access strings from the local and wsgi
applications are identical so the script should connect to the same
database. I encountered problems with create_engine. What type of
exception can this method throw?
The application catches: TypeError, ValueError and OperationalError.
Is there any other Error or some universal sqlalchemy error that can
indicate me where the problem is?
Thanks

On Jul 14, 3:43 pm, King Simon-NFHD78
simon.k...@motorolasolutions.com wrote:
 Eduardo wrote:
  On Jul 14, 10:49 am, King Simon-NFHD78
  simon.k...@motorolasolutions.com wrote:
   Eduardo wrote

When I use the same script with a standalone application it works
  but
when I try to run it as a wsgi application it fails (wsgi logs
  does
not contain any information regarding the failure!)

   Try turning on SQL logging (either by passing echo='debug') to
   create_engine, or by configuring the python logging package as
  described
   onhttp://www.sqlalchemy.org/docs/core/engines.html#configuring-
  logging.
   Then you should see the SQL being issued and the results coming
  back
   from the database.

   How are you configuring transactions? Is it possible that the
   transaction isn't being committed at the end of the web request, so
  any
   changes you've made are being discarded?

   Simon

  My application only queries the database there are no inputs and
  therefore no transactions involved.

 What was the result of turning on SQL logging? Are you sure you're even 
 pointing at the same database that you were when you ran the standalone 
 script? Try printing the value of session.bind.url (or including it in HTTP 
 response, if you don't have easy access to the stdout from your wsgi script)

 Simon

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: information about filed create_engine

2011-07-18 Thread Eduardo
Yes, I use wsgi server of the python library bottle and I don't have
any problem but when I want to use the same script via the apache web
server I get only a server error no exception could be caught not even
by using the code snippet from you (Thanks by the way). I simply
included many print lines that appear in the error log file. The
create_engine fails (I know it from try and except) but I cannot catch
any exception that sheds some light on the reason of the failure.

On Jul 18, 4:06 pm, King Simon-NFHD78
simon.k...@motorolasolutions.com wrote:
  -Original Message-
  From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com]
  On Behalf Of Eduardo
  Sent: 18 July 2011 14:12
  To: sqlalchemy
  Subject: [sqlalchemy] Re: information about filed create_engine

  I dont get any log. The access strings from the local and wsgi
  applications are identical so the script should connect to the same
  database. I encountered problems with create_engine. What type of
  exception can this method throw?
  The application catches: TypeError, ValueError and OperationalError.
  Is there any other Error or some universal sqlalchemy error that can
  indicate me where the problem is?
  Thanks

 I'm sorry - I still don't understand your setup. How do you know that
 you've encountered problems with create_engine if you're not getting
 any kind of exception from it?

 If you really think that create_engine is failing but the exception is
 being caught silently, why not change your code so that you've got an
 exception handler around create_engine:

 try:
     engine = create_engine(your_connection_string)
 except Exception, e:
     import traceback
     log_file = open('/tmp/sqlalchemy_errors', 'w+')
     log_file.write('Exception from create_engine\n')
     log_file.write('%s\n' % e)
     log_file.write(traceback.format_exc())
     raise

 But your life would be much easier if you learnt how to configure
 SQLAlchemy's built-in logging features:

 http://www.sqlalchemy.org/docs/core/engines.html#configuring-logging

 What WSGI server and web framework are you using (if any)? It sounds
 like they are hampering your efforts to debug this. You might find it
 easier to run a very simple wsgi server such as the one in the wsgiref
 module:

 http://docs.python.org/library/wsgiref.html#module-wsgiref.simple_server

 Simon

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: intersect_all vs chaining of filter

2011-07-14 Thread Eduardo
Then what is the purpose of the intersection method? It looks to me as
a (bad) alternative to chained filtering!! Can you think of any case
when intersection is better choice than filters?

On Jun 23, 4:08 am, Mike Conley mconl...@gmail.com wrote:
 On Tue, Jun 21, 2011 at 6:05 AM, Eduardo ruche...@googlemail.com wrote:
  What is the best practice: to chain filters or to collect queries in a
  list and then apply intersect_all()?

 Overall efficiency will depend on the underlying database engine, but I
 can't help but expect that most databases will be more efficient with the
 chained filters query. It would take a really smart optimizer to make the
 intersect method as efficient as the chained filter.

 Using an unrealistic set of queries, but it shows the principle.

 Using intersect_all will generate SQL like this:
     q1 = sess.query(Book).filter(Book.title=='A')
     q2 = sess.query(Book).filter(Book.title=='B')
     q3 = sess.query(Book).filter(Book.title=='C')
     q4 = sess.query(Book).filter(Book.title=='D')
     q5 = q1.intersect_all(q2,q3,q4)

 SELECT anon_1.book_bookid AS anon_1_book_bookid, anon_1.book_title AS
 anon_1_book_title, anon_1.book_authorid AS anon_1_book_authorid
 FROM (SELECT book.bookid AS book_bookid, book.title AS book_title,
 book.authorid AS book_authorid
 FROM book
 WHERE book.title = ? INTERSECT ALL SELECT book.bookid AS book_bookid,
 book.title AS book_title, book.authorid AS book_authorid
 FROM book
 WHERE book.title = ? INTERSECT ALL SELECT book.bookid AS book_bookid,
 book.title AS book_title, book.authorid AS book_authorid
 FROM book
 WHERE book.title = ? INTERSECT ALL SELECT book.bookid AS book_bookid,
 book.title AS book_title, book.authorid AS book_authorid
 FROM book
 WHERE book.title = ?) AS anon_1

 Chaining filters generates this SQL:
     q7 = sess.query(Book).filter(Book.title=='A')
     q7 = q7.filter(Book.title=='B')
     q7 = q7.filter(Book.title=='C')
     q7 = q7.filter(Book.title=='D')

 SELECT book.bookid AS book_bookid, book.title AS book_title, book.authorid
 AS book_authorid
 FROM book
 WHERE book.title = ? AND book.title = ? AND book.title = ? AND book.title =
 ?

 --
 Mike Conley

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: information about filed create_engine

2011-07-14 Thread Eduardo
When I use the same script with a standalone application it works but
when I try to run it as a wsgi application it fails (wsgi logs does
not contain any information regarding the failure!)

On Jul 14, 10:16 am, King Simon-NFHD78
simon.k...@motorolasolutions.com wrote:
 Eduardo wrote



  On Jul 13, 7:11 pm, King Simon-NFHD78
  simon.k...@motorolasolutions.com wrote:
   Eduardo wrote

Hi,
I am trying to prompt an answer from a database after failed
create_engine command. I searched through the source code and I
  found
TypeError, and ValueError returns but they relate (if I
  understood
well only to the access parameters). My problem is that I am sure
that
my access parameters are correct but for some reason the creation
  of
the engine fails. Is there any way to get information why the
  engin
could not be created. The access to db log files is not granted!
Thanks

   What kind of database are you trying to connect to? Are you getting
  a
   Python exception, and if so, can you show us the traceback?

   Simon

  !) PostgresSQL
  2) I don't get any Python exception.

 So how do you know it's failing then?

 Simon

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: information about filed create_engine

2011-07-14 Thread Eduardo
My application only queries the database there are no inputs and
therefore no transactions involved.

On Jul 14, 10:49 am, King Simon-NFHD78
simon.k...@motorolasolutions.com wrote:
 Eduardo wrote



  When I use the same script with a standalone application it works but
  when I try to run it as a wsgi application it fails (wsgi logs does
  not contain any information regarding the failure!)

 Try turning on SQL logging (either by passing echo='debug') to
 create_engine, or by configuring the python logging package as described
 onhttp://www.sqlalchemy.org/docs/core/engines.html#configuring-logging.
 Then you should see the SQL being issued and the results coming back
 from the database.

 How are you configuring transactions? Is it possible that the
 transaction isn't being committed at the end of the web request, so any
 changes you've made are being discarded?

 Simon

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] intersect_all vs chaining of filter

2011-06-21 Thread Eduardo
What is the best practice: to chain filters or to collect queries in a
list and then apply intersect_all()?
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] grouping of a query results after select_all()

2011-06-09 Thread Eduardo
Dear Sirs,
My problem is following as follows I have multiple of queries that I
save in a list. When I have all my queires in the list I apply
intersect_all method
q=qlist[0].intersect_all(*qlist[1:])
I get my result simply by
res=q.all()
However I would like to group results according to some other column
q1=q.group_by(tableints.columns['name'])
However if I try
res=q1.all()
I get the error message meaning that I have to apply group_by for each
of the wueries stored in the list. Is there any way to applygroup_by
only one for all queries in the list?
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Creating table with oracle

2011-02-09 Thread Eduardo
Hi,
I want to create the following table:

 Table('Error', metadata,
Column('Type', String),
Column('reference', String),
Column('context', String),
Column ('Timestamp', DateTime, primary_key=True),)

with the oracle DB. I receive this:

sqlalchemy.exc.Error: (DatabaseError) ORA-00910: specified length too
long for its datatype
 '\nCREATE TABLE Error (\n\tType VARCHAR(None CHAR), \n
\treference VARCHAR(None CHAR), \n\tcontext VARCHAR(None CHAR), \n
\tTimestamp DATE\n)\n\n' {}

I tried it with the postgres it works.
Is there any configuration option that makes the oracle accept this
table without changing the given data types?
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Managing connections for undefined number of parallel processes

2011-01-31 Thread Eduardo
Dear all,
My application create parallel processes that access and query a
database. My problem is that I can not use engine or connection object
in any of these processes because they can not be pickled (requirement
for the input arguments for functions that trigger processes). Is
there any way to use the URL string to identify existing
connection(s). In this case I could use the url to obtain existing
connection and to bind a session created in each process to it. Does
the reducing the number of connections necessarily results in faster
query and storage of the data in a database? Is there any other option
to keep number of connection optimal for an arbitrary number of
processes?
I have seen that there is a way to create an instance of pool class
with the url string - I would like to know if I create this instances
in each of my processes, is a new pool going to be created each time
Pool class has been instantiated?
Thank you

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] pickling an engine onject

2011-01-28 Thread Eduardo
Hi,
I saw that there is a way to serialize a query object is there a way
to serialize an engine object?
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] The number of connection exceeded

2011-01-27 Thread Eduardo
Dear all,
I am writing an application to scan a directory system and store
metadata in DB.
For each directory I create a separate process in which scanning and
metadata feed is performed.
Now I have following problems:
1) I am forced to start a session in each process and bind them for
the engine
   engine = create_engine(dbfile, poolclass=NullPool)
With other poolclass (including default) I get the error that number
of connection are exceeded for the non super users. Is this common
practice to handle this (I mean NullPool) or are there any way to get
around this. How NullPool option affects the performance of the DB?
2)
I create a loop in which various operation are performed (adding,
deleting, updating of each instances):
for elem in mydict:
.
.
session.add(someinst)
.
.
session.delete(inst2)
   .
session.refresh(inst3)

I am concerned about performance issues . Should I commit changes:
after each operation (add, delete, refresh), after each loop or after
the loop has run its course?
Is there any advantage if I create a new session for each operation
and then close it. Is it how the data get faster into the DB?

Thank you in advance



-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] polymorphic single table inheritance with __mapper_args__ automagically set

2010-09-19 Thread Eduardo Robles Elvira
Hello everyone:

I'm having some trouble with polymorphic single table inheritance. I
want my subclasses (Ferrari is a subclass of Car) to have the
__mapper_args__ automatically set. How could I do that. I've got this:


class Car(Base):
__tablename__ = 'car'
id = Column(Integer, primary_key=True)
class_name = Column(Unicode(128), nullable=False)
__mapper_args__ = {polymorphic_on:class_name,
polymorphic_identity:Car, with_polymorphic:*}

#...@classproperty
#def __mapper_args__(cls):
#if cls.__name__ == Car:
#return {polymorphic_on:cls.class_name,
polymorphic_identity:Car, with_polymorphic:*}
#else:
#return {polymorphic_identity:cls.__name__}

parent_id = Column(Integer, ForeignKey('car.id'))
children = relation(Car,  backref=backref('parent', remote_side=id))

def __init__(self):
pass

def max_speed(self):
return 1000 km/h

class Ferrari(Car):
__mapper_args__ = {polymorphic_identity:Ferrari}
def __init__(self):
Car.__init__(self)

def max_speed(self):
return 320 km/h

I know that it doesn't make much sense for a car to have parent and
children cars, but that's what I need. So once the tables are created
in the db, I do something like:

parent_car = Car()
child_car = Ferrari()
child_car.parent = parent_car
orm.add(parent_car)
orm.add(child_car)
orm.commit()
print parent_car.children[0].max_speed()
print orm.query(Car).filter(Car.id ==
parent_car.children[0].id).one().max_speed()

And it works fine (prints 320 km/h twice)... but if I comment out
the __mapper_args__ lines in Car and Ferrari and uncomment the
@classproperty, it doesn't work fine because class_type doesn't get
properly set (i.e. its value is None) and I get a class_type cannot
be NULL exception. How could I fix it?

Thanks in advance,
Eduardo.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: Polymorphic across foreign key

2010-08-22 Thread Eduardo Robles Elvira
On May 15 2008, 6:27 pm, Michael Bayer mike...@zzzcomputing.com
wrote:
 On May 15, 2008, at 12:12 PM, J. Cliff Dyer wrote:
  How can I use this field for polymorphism?  Is it possible?

 polymorphicdiscriminators are currently table-local scalar columns.  
 So if you had a many-to-one of discriminators, youd currently have to  
 encode the discriminator to the primarykeyidentifier of each  
 discriminotor.  We will eventually allow a python function to be used  
 as a discriminator as well which you can use to add a level of  
 abstraction to this (you'd preload the list of discriminiator objects  
 and again map based on primarykey).

Hello!

Two years later.. :P Are we going to get a python function to be used
as a discriminator soon? I would think that it would not be very
difficult to implement, right? As shown in my previous emails in the
thread Model factory, that would solve my problem. I have the python
function already written, but I don't know how to make sqlalchemy call
to it. I thought that using a composite field should work, but it
doesn't because as you say, it's not a table-local scalar column. If
the problem is the proxy_set is not set, maybe I can set the proxy_set
var to the composite_field somehow?

Regards,
   Eduardo Robles Elvira.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Model factory

2010-08-20 Thread Eduardo Robles Elvira
On Fri, Aug 20, 2010 at 10:34 AM, Daniel Kluev dan.kl...@gmail.com wrote:

 On Fri, Aug 20, 2010 at 7:39 AM, Eduardo Robles Elvira edu...@gmail.com
 wrote:

 Now, these functions reimplemented in the inherited class models might
 be called by the jobs view. It would be very convenient if directly
 when I get the jobs from the database with sqlalchemy I could directly
 get them in CustomJobA, CustomJobB instances, instead of all being
 instances from the base clas Job. There's a field in the base Job
 class which tells me which class type it is (basically, it's
 path.to.module and then ClassName).


 SQLAlchemy supports this out of the box.
 http://www.sqlalchemy.org/docs/reference/ext/declarative.html#single-table-inheritance

 So it will be something like this:

 class Job(Base):
     class_name = Column(Unicode(64))
     __mapper_args__ = {'polymorphic_on': class_name}

 class CustomJobA(Job):
     __mapper_args__ = {'polymorphic_identity': 'CustomJobA'}

 SQLAlchemy will then load correct class instance for you on queries,
 depending on the value of the field.

 --
 With best regards,
 Daniel Kluev

Thanks Diez and Daniel for the responses. It seems that this is the
way to go, but it's not quite there yet: now I can indeed load the
correct lass instance for my queries, but it seems to be restricted to
inherited classes already loaded in my current module. What would like
to do is being to do something more similar to (conceptually!):


class Job(Base):
class_path = Column(Unicode(64)) # for example CustomJobA
module_path = Column(Unicode(64)) # maybe plugins.myplugin.path.to.module

def get_class_name(self):
  modz = __import__(self.module_path, fromlist=[True])
  clazz  = getattr(modz, self.class_path)
 globals()[clazz.__name__] = clazz
class_name = property(get_class_name)
__mapper_args__ = {'polymorphic_on': class_name}


then, in plugins/myplugin/path/to/module.py:

class CustomJobA(Job):
__mapper_args__ = {'polymorphic_identity': 'CustomJobA'}

Where I don't necessary have the class CustomJobA from module
plugins.myplugin.path.to.module imported in the first place, but it
will be loaded. Of course, what I just wrote up there seems reaally
hacky and probably there's a better way? To be honest, I haven't even
tested if it even works yet.

Regards,
Eduardo RE.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Model factory

2010-08-19 Thread Eduardo Robles Elvira
Hello everyone:

This is my first post in this mailing list/group. My question is
simple: is there some way to tell sqlalchemy which method should be
called to instance models? Now, some background:

I'm working in a project with plugins support. In the project core
I've got a Job class model. There's also a model view (I'm using
web.py) which shows information about the jobs.

Plugins can extend the Jobs, inheriting from them. They won't need to
add any new column to the model, just reimplement some base functions
for convenience. So I might have the class CustomJob which inherits
the model  class Job.

Now, these functions reimplemented in the inherited class models might
be called by the jobs view. It would be very convenient if directly
when I get the jobs from the database with sqlalchemy I could directly
get them in CustomJobA, CustomJobB instances, instead of all being
instances from the base clas Job. There's a field in the base Job
class which tells me which class type it is (basically, it's
path.to.module and then ClassName).

I can define a factory method that given a base job instance, or
something similar, can return an instance of the correct model. The
simplest way to work around this problem is to put that function as a
member function called def instance(self): inside the base Job class,
and then anyone who needs it calls job.instance() to get an instance
of the needed class, but it's a bit troublesome. I'd like it to be
more transparent. The job instance should be given to me directly of
the class type needed.

So the question I mentioned earlier remains: is there some way to tell
sqlalchemy which method should be called to instance models? I've seen
http://www.sqlalchemy.org/docs/reference/ext/declarative.html#inheritance-configuration
and 
http://www.sqlalchemy.org/docs/reference/ext/declarative.html#class-constructor
but there doesn't seem to be a straightforward to do what I need. Also
I saw that someone in this list did something similar, but much more
complicated: 
http://groups.google.com/group/sqlalchemy/browse_thread/thread/9dfa457a7903f684/dd102bcb86dd905b

Any ideas, suggestions?

Regards,
   Eduardo RE

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: SQLAlchemy Sphinx Documentation Preview

2008-12-05 Thread Eduardo Schettino

Hi,

There are some sphinx system messages on:
http://www.sqlalchemy.org/docs/sphinxtest/intro.html


Reference Documentation¶

*

  System Message: WARNING/2
(/home/classic/dev/sphinx/doc/build/intro.rst)
  undefined label: datamapping – if you don't give a link
caption the label must precede a section header.
  - A comprehensive walkthrough of major ORM patterns and techniques.
*

  System Message: WARNING/2
(/home/classic/dev/sphinx/doc/build/intro.rst)
  undefined label: session – if you don't give a link caption
the label must precede a section header.
  - A detailed description of SQLAlchemy's Session object
*

  System Message: WARNING/2
(/home/classic/dev/sphinx/doc/build/intro.rst)
  undefined label: engines – if you don't give a link caption
the label must precede a section header.
  - Describes SQLAlchemy's database-connection facilities,
including connection documentation and working with connections and
transactions.
*

  System Message: WARNING/2
(/home/classic/dev/sphinx/doc/build/intro.rst)
  undefined label: pooling – if you don't give a link caption
the label must precede a section header.
  - Further detail about SQLAlchemy's connection pool library.



On Wed, Dec 3, 2008 at 11:36 PM, Michael Bayer [EMAIL PROTECTED] wrote:

 We've created a new branch and are in the process of migrating all of
 our documentation over to Sphinx.   The process has gone well and we
 have a working demo of the full system online.  By converting to
 Sphinx, we get the huge advantage of being on a standardized platform
 that everyone can understand and contribute towards.  All kinds of
 wacky old code, some of it four or more years old, has been removed
 (and we thank it for its service).   The docs are now split into Main
 Documentation and API Reference.  Because Sphinx allows very
 flexible layout of docstring-generated documentation, Main
 Documentation is shrinking and the docstrings used by API
 Reference, which is an all new section that replaces the old
 straight down modules display, are growing dramatically, which means
 more documentation is centralized across the site/pydocs and there's
 less redundancy.

 What we are now looking for with regards to the demo is:

- comments/suggestions regarding layout, styling.  Some layout
 changes were forced by Sphinx,  and others (most) are improvements
 that Sphinx allowed us to achieve.  I'm not a CSS guru or a designer
 so suggested patches to the CSS and templates would be welcome.   If
 Todd Grimason is out there, feel free to chime in :) .

- proofreaders.  The content on the demo is maybe 60% of the way
 there and we're combing through finding issues related to the Sphinx
 conversion, as well as things that have just been wrong all along.
 We would love to get patches against the doc build correcting as many
 issues as possible.

- authors.   No excuses now , we're on the most standard platform
 there is for docs.  If you have better verbiage for sections or
 docstrings which aren't clear, are nonexistent (like many of the
 dialects) or are out of date (theres lots), we want to see
 suggestions.  More elaborate suggestions regarding new sections and
 organization are welcome too as the structure is completely open ended.

- people who understand LaTex to work on the PDF side of things.
 This one's totally over my head as far as how to get a pdf file out of
 this thing (pdflatex is fairly inscrutable on a mac).

 Sphinx 0.6 is required, which at the time of this writing is not yet
 released so you'll have to check out Sphinx from its mercurial
 repository if you want to do builds.

 View the content online at: http://www.sqlalchemy.org/docs/sphinxtest/
 Checkout the SVN branch and do a build:  
 http://svn.sqlalchemy.org/sqlalchemy/branches/sphinx

 


--~--~-~--~~~---~--~~
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 more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---