[sqlalchemy] Re: Elixir performance

2007-09-06 Thread Gaetan de Menten

On 9/5/07, Paul Johnston [EMAIL PROTECTED] wrote:

 data.  I did some benchmarks a while back to see how everything
 stacked up as I was wondering if I was doing everything the hard way
 (in C++) instead of using SqlAlchemy, etc.  TurboEntity is the same as
 
 
 Great work Eric.

 I am quite surprised at the results. I would have thought
 ActiveMapper/TurboEntity would only be marginally slower than plain
 SQLAlchemy.

To make this really clear (even though Michael said it already),
ActiveMapper, TurboEntity and Elixir are not any slower than SA ORM.
What is slower is SA ORM compared to SA SQL layer. In fact, Elixir
querying system *is* SQLAlchemy proper.

-- 
Gaëtan de Menten
http://openhex.org

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: [patch] max() arg is an empty sequence while trying to reflect bugzilla table

2007-09-06 Thread Marcin Kasperski

Michael Bayer [EMAIL PROTECTED] writes:

 hey Marcin -

 Seems like Jason Kirtland is out today.  Any chance you could add a  
 simple test case to test/dialect/mysql.py for this ? 

Seems he already did this ;-) And he also improved my patch, in the
meantime I discovered that while my patch was sufficient to avoid the
failure, internally enum values were not correctly extracted (noticed
this while inspecting in the debugger, not sure whether it is of any
importance, I'm still new to sqlalchemy).

Thanks for the fast fix (well, and for the whole work on the package).



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] max/coalesce bug in 0.4?

2007-09-06 Thread Koen Bok

Hi there, I am upgrading my app to 0.4 and while it's going pretty
well, I encountered something strange.

I have the following code:

request_table = Table('request', metadata,
Column('id', Integer, primary_key=True),
...
Column('metanumberstate', Integer, nullable=False,
default=func.coalesce(func.max(metanumber_table.c.id), 0)),
...
)

And this is bound to the Request object. But when I init a new
instance and commit it I get an error (see below). But this always
worked (0.3.x) so I have no clue what I am doing wrong. Anyone has a
hint?

ProgrammingError: (ProgrammingError) missing FROM-clause entry for
table metanumber
LINE 1: ...uest), NULL, 5, 1, 2, 3, 2, NULL, 7,
coalesce(max(metanumber...
 ^
 'INSERT INTO request (id, number, id_parent, id_item, id_employee,
id_terminal, id_location, srcstocktype, dststocktype, metadatastate,
metanumberstate, metataxstate, quantity, discount, over ride_price,
allocation, date, is_business, has_tax, is_quote) VALUES (%(id)s,
(SELECT coalesce(max(number), 0) + 1 FROM request), %(id_parent)s, %
(id_item)s, %(id_employee)s, %(id_terminal)s, %(id_location)s, %
(srcstocktype)s, %(dststocktype)s, %(metadatastate)s,
coalesce(max(metanumber.id), %(coalesce)s), coalesce(max(metatax.id), %
(coalesce_1)s), %(quantity)s, %(discount)s, %(override_price)s, %
(allocation)s, now(), %(is_business)s, %(has_tax)s, %
(is_quote)s)' {'id_item': 5L, 'is_business': False, 'srcstocktype': 2,
'is_quote': False, 'coalesce_1': 0, 'id_terminal': 2L, 'id_parent':
None, 'id_employee': 1L, 'allocation': 0, 'coalesce': 0,
'id_location': 3L, 'has_tax': True, 'override_price': None,
'dststocktype': None, 'discount': None, 'quantity': 1, 'id': 1L,
'metadatastate': 7L}


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: max/coalesce bug in 0.4?

2007-09-06 Thread Michael Bayer

all the default SQL functions are being executed inline here.  so  
it doesnt like aggregates like max being placed into defaults like  
that.

the best I can do for you here, other than rolling back the entire  
inilne default thing, would look like this:

Column('foo', Integer, ColumnDefault(func.coalesce(func.max 
(metanumber_table.c.id), 0), inline=False))

so that it gets the hint to pre-execute that default.


On Sep 6, 2007, at 8:44 AM, Koen Bok wrote:


 Hi there, I am upgrading my app to 0.4 and while it's going pretty
 well, I encountered something strange.

 I have the following code:

 request_table = Table('request', metadata,
   Column('id', Integer, primary_key=True),
   ...
   Column('metanumberstate', Integer, nullable=False,
   default=func.coalesce(func.max(metanumber_table.c.id), 0)),
   ...
   )

 And this is bound to the Request object. But when I init a new
 instance and commit it I get an error (see below). But this always
 worked (0.3.x) so I have no clue what I am doing wrong. Anyone has a
 hint?

 ProgrammingError: (ProgrammingError) missing FROM-clause entry for
 table metanumber
 LINE 1: ...uest), NULL, 5, 1, 2, 3, 2, NULL, 7,
 coalesce(max(metanumber...
  ^
  'INSERT INTO request (id, number, id_parent, id_item, id_employee,
 id_terminal, id_location, srcstocktype, dststocktype, metadatastate,
 metanumberstate, metataxstate, quantity, discount, over ride_price,
 allocation, date, is_business, has_tax, is_quote) VALUES (%(id)s,
 (SELECT coalesce(max(number), 0) + 1 FROM request), %(id_parent)s, %
 (id_item)s, %(id_employee)s, %(id_terminal)s, %(id_location)s, %
 (srcstocktype)s, %(dststocktype)s, %(metadatastate)s,
 coalesce(max(metanumber.id), %(coalesce)s), coalesce(max 
 (metatax.id), %
 (coalesce_1)s), %(quantity)s, %(discount)s, %(override_price)s, %
 (allocation)s, now(), %(is_business)s, %(has_tax)s, %
 (is_quote)s)' {'id_item': 5L, 'is_business': False, 'srcstocktype': 2,
 'is_quote': False, 'coalesce_1': 0, 'id_terminal': 2L, 'id_parent':
 None, 'id_employee': 1L, 'allocation': 0, 'coalesce': 0,
 'id_location': 3L, 'has_tax': True, 'override_price': None,
 'dststocktype': None, 'discount': None, 'quantity': 1, 'id': 1L,
 'metadatastate': 7L}


 


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Elixir performance

2007-09-06 Thread Michael Bayer

since performance is the hot topic these days, I thought Id note that  
I've made some ORM improvements in the current SQLAlchemy trunk.   We  
have a profiling test that loads 10 objects each with 50 child  
objects, eagerly loaded across 500 rows.  Version 0.3.10 uses 70040  
function calls, 0.4beta5 uses 53173, and trunk uses 37403.   beta6  
should feel pretty quick.


On Sep 6, 2007, at 3:11 AM, Gaetan de Menten wrote:


 On 9/5/07, Paul Johnston [EMAIL PROTECTED] wrote:

 data.  I did some benchmarks a while back to see how everything
 stacked up as I was wondering if I was doing everything the hard way
 (in C++) instead of using SqlAlchemy, etc.  TurboEntity is the  
 same as


 Great work Eric.

 I am quite surprised at the results. I would have thought
 ActiveMapper/TurboEntity would only be marginally slower than plain
 SQLAlchemy.

 To make this really clear (even though Michael said it already),
 ActiveMapper, TurboEntity and Elixir are not any slower than SA ORM.
 What is slower is SA ORM compared to SA SQL layer. In fact, Elixir
 querying system *is* SQLAlchemy proper.

 -- 
 Gaëtan de Menten
 http://openhex.org

 


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: max/coalesce bug in 0.4?

2007-09-06 Thread Koen Bok

Tried that, but it just places the select statement within the insert
statement without brackets:

2007-09-06 18:00:57,603 INFO sqlalchemy.engine.base.Engine.0x..90
INSERT INTO request (id, metanumberstate) VALUES (%(id)s, SELECT
coalesce(max(metanumber.id), %(coalesce)s)
FROM metanumber)
2007-09-06 18:00:57,604 INFO sqlalchemy.engine.base.Engine.0x..90
{'coalesce': 0, 'id': 1L}
2007-09-06 18:00:57,609 INFO sqlalchemy.engine.base.Engine.0x..90
ROLLBACK

If I put the brackets in by hand, it works fine...

On Sep 6, 5:53 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On Sep 6, 2007, at 10:28 AM, Koen Bok wrote:



  Aight, that would be cool. So this still has to be implemented then,
  right?

 embedded select works eh ?  try making your default that:

 default=select([func.max(metanumber.id)])


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: max/coalesce bug in 0.4?

2007-09-06 Thread Michael Bayer

OK that one is fixed in r3467.

On Sep 6, 2007, at 12:02 PM, Koen Bok wrote:


 Tried that, but it just places the select statement within the insert
 statement without brackets:

 2007-09-06 18:00:57,603 INFO sqlalchemy.engine.base.Engine.0x..90
 INSERT INTO request (id, metanumberstate) VALUES (%(id)s, SELECT
 coalesce(max(metanumber.id), %(coalesce)s)
 FROM metanumber)
 2007-09-06 18:00:57,604 INFO sqlalchemy.engine.base.Engine.0x..90
 {'coalesce': 0, 'id': 1L}
 2007-09-06 18:00:57,609 INFO sqlalchemy.engine.base.Engine.0x..90
 ROLLBACK

 If I put the brackets in by hand, it works fine...

 On Sep 6, 5:53 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On Sep 6, 2007, at 10:28 AM, Koen Bok wrote:



 Aight, that would be cool. So this still has to be implemented then,
 right?

 embedded select works eh ?  try making your default that:

 default=select([func.max(metanumber.id)])


 


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] datetime objects unique by date(disregarding time)

2007-09-06 Thread Pedro Algarvio, aka, s0undt3ch

How could one get only the unique dates from a datetime column, disregarding 
the time part of the datetime object?

I know I can do:
 s = model.sqla.select([model.channel_events.c.stamp], 
 model.channel_events.c.channel_participation_id == 5)
 results = model.Session.execute(s).fetchall()
 for res in results:
... print res
...
(datetime.datetime(2007, 9, 4, 11, 44, 8, 199613, 
tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9eb8c),)
(datetime.datetime(2007, 9, 3, 19, 7, 51, 147560, 
tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9ef8c),)
(datetime.datetime(2007, 9, 4, 12, 5, 44, 654299, 
tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9efcc),)
(datetime.datetime(2007, 9, 4, 12, 7, 30, 279193, 
tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9ee6c),)
(datetime.datetime(2007, 9, 4, 12, 18, 48, 106636, 
tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9ef2c),)
(datetime.datetime(2007, 9, 4, 12, 20, 38, 63371, 
tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9ec6c),)
(datetime.datetime(2007, 9, 4, 12, 20, 40, 271526, 
tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca30cc),)
(datetime.datetime(2007, 9, 4, 12, 22, 55, 752780, 
tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca304c),)
(datetime.datetime(2007, 9, 4, 12, 57, 19, 88308, 
tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca30ac),)
(datetime.datetime(2007, 9, 4, 13, 26, 19, 226345, 
tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3bcc),)
(datetime.datetime(2007, 9, 4, 10, 38, 13, 598636, 
tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3c2c),)
(datetime.datetime(2007, 9, 4, 10, 47, 5, 961859, 
tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3c8c),)
(datetime.datetime(2007, 9, 4, 10, 47, 48, 8467, 
tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3cec),)
(datetime.datetime(2007, 9, 4, 11, 31, 55, 254280, 
tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3d4c),)
(datetime.datetime(2007, 9, 4, 11, 41, 11, 196310, 
tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3dac),)
 len(results)
15
 len(set([date[0].date() for date in results]))
2


But I'm sure this can be done differently.

If it makes a difference I'm using postgres as the backend.

Best Regards,
-- 
Pedro Algarvio
   __ ___  ___ ______ __
|   Y   .'  _|   _   .-.'  _|  |_   .-..-.
|.  |   |   _|   1___|  _  |   _|   _|__|  _  |   _|  _  |
|.  |   |__| |   |_|__| ||__|_|__| |___  |
|:  1   ||:  1   | |_|
|::.. . ||::.. . |  ufs [AT] ufsoft [DOT] org
`---'`---'ufs [AT] sapo [DOT] pt


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: [patch] max() arg is an empty sequence while trying to reflect bugzilla table

2007-09-06 Thread jason kirtland

Marcin wrote:
 Seems he already did this ;-) And he also improved my patch, in
 the meantime I discovered that while my patch was sufficient to
 avoid the failure, internally enum values were not correctly
 extracted (noticed this while inspecting in the debugger, not
 sure whether it is of any importance, I'm still new to
 sqlalchemy).

 Thanks for the fast fix (well, and for the whole work on the
 package).

Thanks for the spot!  This reflection code is all-new in 0.4, 
totally redone to allow reflection in a single server round-trip. 
The more schemas it goes up against in beta the better, although 
I'm fairly optimistic about the general correctness.

I also just spotted and fixed an ancient corner case for enum 
values while reviewing the r3464 patch for the bugzilla schema, so 
double thanks.  :)

Cheers,
Jason


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: datetime objects unique by date(disregarding time)

2007-09-06 Thread Michael Bayer

you can probably select on DISTINCT trunc(day, somedate)

SA would do this like  select([distinct(func.trunc(day,  
mytable.c.datecol))])



On Sep 6, 2007, at 1:37 PM, Pedro Algarvio, aka, s0undt3ch wrote:


 How could one get only the unique dates from a datetime column,  
 disregarding the time part of the datetime object?

 I know I can do:
 s = model.sqla.select([model.channel_events.c.stamp],  
 model.channel_events.c.channel_participation_id == 5)
 results = model.Session.execute(s).fetchall()
 for res in results:
 ... print res
 ...
 (datetime.datetime(2007, 9, 4, 11, 44, 8, 199613,  
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9eb8c),)
 (datetime.datetime(2007, 9, 3, 19, 7, 51, 147560,  
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9ef8c),)
 (datetime.datetime(2007, 9, 4, 12, 5, 44, 654299,  
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9efcc),)
 (datetime.datetime(2007, 9, 4, 12, 7, 30, 279193,  
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9ee6c),)
 (datetime.datetime(2007, 9, 4, 12, 18, 48, 106636,  
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9ef2c),)
 (datetime.datetime(2007, 9, 4, 12, 20, 38, 63371,  
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9ec6c),)
 (datetime.datetime(2007, 9, 4, 12, 20, 40, 271526,  
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca30cc),)
 (datetime.datetime(2007, 9, 4, 12, 22, 55, 752780,  
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca304c),)
 (datetime.datetime(2007, 9, 4, 12, 57, 19, 88308,  
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca30ac),)
 (datetime.datetime(2007, 9, 4, 13, 26, 19, 226345,  
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3bcc),)
 (datetime.datetime(2007, 9, 4, 10, 38, 13, 598636,  
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3c2c),)
 (datetime.datetime(2007, 9, 4, 10, 47, 5, 961859,  
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3c8c),)
 (datetime.datetime(2007, 9, 4, 10, 47, 48, 8467,  
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3cec),)
 (datetime.datetime(2007, 9, 4, 11, 31, 55, 254280,  
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3d4c),)
 (datetime.datetime(2007, 9, 4, 11, 41, 11, 196310,  
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3dac),)
 len(results)
 15
 len(set([date[0].date() for date in results]))
 2


 But I'm sure this can be done differently.

 If it makes a difference I'm using postgres as the backend.

 Best Regards,
 -- 
 Pedro Algarvio
__ ___  ___ ______ __
 |   Y   .'  _|   _   .-.'  _|  |_   .-..-.
 |.  |   |   _|   1___|  _  |   _|   _|__|  _  |   _|  _  |
 |.  |   |__| |   |_|__| ||__|_|__| |___  |
 |:  1   ||:  1   | |_|
 |::.. . ||::.. . |  ufs [AT] ufsoft [DOT] org
 `---'`---'ufs [AT] sapo [DOT] pt


 


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] sqlalchemy.select() and tablename.select() why are they different?

2007-09-06 Thread Lukasz Szybalski

Hello,
So it seems to me there are two select function that I can use but
they are different
First:
s=Users.select(Users.c.LASTNAME=='Smith')
but when you want to select only two columns via :
s=Users.select([Users.c.LASTNAME, Users.c.FIRSTNAME], Users.c.LASTNAME
=='Smith')

you get an error :
 File /usr/lib/python2.4/site-packages/sqlalchemy/ext/assignmapper.py,
line 7, in do
return getattr(query, name)(*args, **kwargs)
TypeError: select() takes at most 2 arguments (3 given)


Second:

import sqlalchemy
s2=sqlalchemy.select(Users.c.LASTNAME=='Smith')
s3=s2.execute()
This works just fine:
s2=sqlalchemy.select([Users.c.LASTNAME, Users.c.FIRSTNAME],
Users.c.LASTNAME =='Smith')
s3=s2.execute()

Is this difference suppose to be there? or is it a bug in assign_mapper?

Lucas


-- 
http://lucasmanual.com/mywiki/TurboGears

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: datetime objects unique by date(disregarding time)

2007-09-06 Thread Mike Orr

On 9/6/07, Pedro Algarvio, aka, s0undt3ch [EMAIL PROTECTED] wrote:

 How could one get only the unique dates from a datetime column, disregarding 
 the time part of the datetime object?

MySQL has a DATE() function that chops off the time part.  I don't
know if Postgres has the same.

 import datetime
 import sqlalchemy as sa
 e = sa.create_engine(mysql://...)
 e.execute(select date('2007-01-20 10:22:45')).fetchone()[0]
datetime.date(2007, 1, 20)
 sql = sa.select([sa.func.date('2007-01-20 10:22:45')])
 e.execute(sql).fetchone()[0]
datetime.date(2007, 1, 20)
 e.execute(sql).fetchone()[0] == datetime.date(2007, 1, 20)
True

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: datetime objects unique by date(disregarding time)

2007-09-06 Thread jason kirtland

Some other postgres-friendly options from the IRC channel:

select([func.date(model.channel_events.c.stamp)], distinct=True)
  or
select([cast(model.channel_events.c.stamp, Date)], distinct=True)

The latter should be portable anywhere, I think.  Not sure about 
the first beyond the 3 usual open source suspects.


Michael wrote:

 you can probably select on DISTINCT trunc(day, somedate)

 SA would do this like  select([distinct(func.trunc(day,
 mytable.c.datecol))])



 On Sep 6, 2007, at 1:37 PM, Pedro Algarvio, aka, s0undt3ch wrote:


 How could one get only the unique dates from a datetime column,
 disregarding the time part of the datetime object?

 I know I can do:
 s = model.sqla.select([model.channel_events.c.stamp],
 model.channel_events.c.channel_participation_id == 5)
 results = model.Session.execute(s).fetchall()
 for res in results:
 ... print res
 ...
 (datetime.datetime(2007, 9, 4, 11, 44, 8, 199613,
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9eb8c),)
 (datetime.datetime(2007, 9, 3, 19, 7, 51, 147560,
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9ef8c),)
 (datetime.datetime(2007, 9, 4, 12, 5, 44, 654299,
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9efcc),)
 (datetime.datetime(2007, 9, 4, 12, 7, 30, 279193,
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9ee6c),)
 (datetime.datetime(2007, 9, 4, 12, 18, 48, 106636,
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9ef2c),)
 (datetime.datetime(2007, 9, 4, 12, 20, 38, 63371,
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8c9ec6c),)
 (datetime.datetime(2007, 9, 4, 12, 20, 40, 271526,
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca30cc),)
 (datetime.datetime(2007, 9, 4, 12, 22, 55, 752780,
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca304c),)
 (datetime.datetime(2007, 9, 4, 12, 57, 19, 88308,
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca30ac),)
 (datetime.datetime(2007, 9, 4, 13, 26, 19, 226345,
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3bcc),)
 (datetime.datetime(2007, 9, 4, 10, 38, 13, 598636,
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3c2c),)
 (datetime.datetime(2007, 9, 4, 10, 47, 5, 961859,
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3c8c),)
 (datetime.datetime(2007, 9, 4, 10, 47, 48, 8467,
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3cec),)
 (datetime.datetime(2007, 9, 4, 11, 31, 55, 254280,
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3d4c),)
 (datetime.datetime(2007, 9, 4, 11, 41, 11, 196310,
 tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0x8ca3dac),)
 len(results)
 15
 len(set([date[0].date() for date in results]))
 2


 But I'm sure this can be done differently.

 If it makes a difference I'm using postgres as the backend.

 Best Regards,
 --
 Pedro Algarvio
__ ___  ___ ______ __
 |   Y   .'  _|   _   .-.'  _|  |_   .-..-.
 |.  |   |   _|   1___|  _  |   _|   _|__|  _  |   _|  _  |
 |.  |   |__| |   |_|__| ||__|_|__| |___  |
 |:  1   ||:  1   | |_|
 |::.. . ||::.. . |  ufs [AT] ufsoft [DOT] org
 `---'`---'ufs [AT] sapo [DOT] pt


 


 



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: sqlalchemy.select() and tablename.select() why are they different?

2007-09-06 Thread sdobrev

On Thursday 06 September 2007 23:03:35 Lukasz Szybalski wrote:
 Hello,
 So it seems to me there are two select function that I can use but
 they are different
 First:
 s=Users.select(Users.c.LASTNAME=='Smith')
 but when you want to select only two columns via :
 s=Users.select([Users.c.LASTNAME, Users.c.FIRSTNAME],
 Users.c.LASTNAME =='Smith')

 you get an error :
  File
 /usr/lib/python2.4/site-packages/sqlalchemy/ext/assignmapper.py,
 line 7, in do
 return getattr(query, name)(*args, **kwargs)
 TypeError: select() takes at most 2 arguments (3 given)




 Second:

 import sqlalchemy
 s2=sqlalchemy.select(Users.c.LASTNAME=='Smith')
 s3=s2.execute()
 This works just fine:
 s2=sqlalchemy.select([Users.c.LASTNAME, Users.c.FIRSTNAME],
 Users.c.LASTNAME =='Smith')
 s3=s2.execute()

 Is this difference suppose to be there? or is it a bug in
 assign_mapper?

 Lucas


the first is the ORM query().select() taking only where clause, the 
second is plain sql select(columns,where,from). To disambiguate, 
first one is discontinued and is replaced by filter().

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] bitemporal mixin recipe in dbcook

2007-09-06 Thread sdobrev

hi.

For those interested, i've put a bitemporal mixin class under 
dbcook/misc/timed2/. It handles Objects with multiple versions 
(history), disabled/enabled state, and stays sane with  
same-timestamp-versions.

The available queries are:
 - get_time_clause( times):
return the clause to get the object-version for that timestamps;
use to (further) filter some SA.query()
 - klas.allinstances( times ):
return the last valid versions of all objects for the 
(bitemporal) timestamp
 - klas.get_obj_history_in_range( objid, fromtimes, totimes):
return all versions of that Object within given timesrange

It uses plain SA - as long as u maintain the required object 
attributes, it should work no matter how they appeared (by 
dbcook/elixir/whatever/manual).

Required attributes:
   objid  - this keeps track of which versions belong to same Object. 
This should be incremented by special means, only when new Object is 
made (and not when new version of existing Object)
   time_trans, time_valid  - the two temporal dimensions. can be 
anything orderable - numbers, floats, strings, datetime, ...
   disabled - a boolean 
plus some class-setup is required, see begin of class Timed2Mixin.

It is there together with quite thorough test, and a complementary 
timed/ library, containing things like timed1 and timed2 
implementations over (python) sequences, timed* versioning support 
for python modules, some timedcontext etc.

todo: as ever, some documentation, and simple examples

svn co 
https://dbcook.svn.sourceforge.net/svnroot/dbcook/trunk/dbcook/misc/timed2/
https://dbcook.svn.sourceforge.net/svnroot/dbcook/trunk
http://dbcook.sourceforge.net/

ciao
svilen

p.s. something learned around minor fix in dbcook.usage.sa2static: 
delattr( Myclass, attrname) calls Myclass' metaclass.__delattr__(), 
probably same goes for setattr. Thus the setting and clearing of 
InstrumentedAttributes can be controlled, maintaning/restoring the 
overriden original descriptors if any.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: sqlalchemy.select() and tablename.select() why are they different?

2007-09-06 Thread Lukasz Szybalski

On 9/6/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 On Thursday 06 September 2007 23:03:35 Lukasz Szybalski wrote:
  Hello,
  So it seems to me there are two select function that I can use but
  they are different
  First:
  s=Users.select(Users.c.LASTNAME=='Smith')
  but when you want to select only two columns via :
  s=Users.select([Users.c.LASTNAME, Users.c.FIRSTNAME],
  Users.c.LASTNAME =='Smith')
 
  you get an error :
   File
  /usr/lib/python2.4/site-packages/sqlalchemy/ext/assignmapper.py,
  line 7, in do
  return getattr(query, name)(*args, **kwargs)
  TypeError: select() takes at most 2 arguments (3 given)


 
 
  Second:
 
  import sqlalchemy
  s2=sqlalchemy.select(Users.c.LASTNAME=='Smith')
  s3=s2.execute()
  This works just fine:
  s2=sqlalchemy.select([Users.c.LASTNAME, Users.c.FIRSTNAME],
  Users.c.LASTNAME =='Smith')
  s3=s2.execute()
 
  Is this difference suppose to be there? or is it a bug in
  assign_mapper?
 
  Lucas


 the first is the ORM query().select() taking only where clause, the
 second is plain sql select(columns,where,from). To disambiguate,
 first one is discontinued and is replaced by filter().

So basically the first one does select * from x where y =?
And you can only substitute x,y,? (Sounds very limiting)

To me TABLENAME.select() should just be a a wrapper to
sqlalchemy.select().execute()

That way the first accepts the same parameters as before but it will
also be able to do where and from..??? Yes No?

I am not sure what filter() will be doing differently. I check the
docs and it sounds to me like you want to filter the results already
selected?Doesn't that complicate things even more. No I have to know a
filter function and find out what parameters does it take?  Will
filter() do the actual select ? How will it be different from query()
select()? Why are they separated?

I guess this is similar conversation:
http://groups.google.com/group/sqlalchemy/browse_thread/thread/be0b4d6d793cd6f7/4a283669530e1e86?#4a283669530e1e86

From the docs it seems as with filter you will have to do this to get
your select statement. That seems to me is over complicating things.
First you call query then subfunction filter then subfunction order
then subfunction all? how many levels does it go to?

session.query(User).filter(User.c.user_name.in_('Ed',
'Harry','Mary')).order_by(User.c.user_name).all()


Wouldn't it be easier if we do:
s2=Users.select(
Users.c.LASTNAME =='Smith'
)
or
s2=Users.select(
[Users.c.LASTNAME, Users.c.FIRSTNAME],
Users.c.LASTNAME =='Smith'
)
or
s2=Users.select(
[Users.c.LASTNAME, Users.c.FIRSTNAME],
Users.c.LASTNAME =='Smith',
order_by(User.c.FIRSTNAME)
)
or
s2=Users.select(
[Users.c.LASTNAME, Users.c.FIRSTNAME],
Users.c.LASTNAME =='Smith',
order_by(User.c.FIRSTNAME,ASC),
limit(1)
)

there would be another option for  join, etc that could be included in
the list if one needed to use more. Each of them are optional.

Otherwise questions arise:
which one do i do  filter(), filter_by(), query() select() select_by()
Is order_by a passed in parameter or function of a filter() or query()
or is it ?
Why do I have to specify all()? Shouldn't  that be a default?
What is the order of functions to call? Which one is used on what?

What you guys think?

Lucas

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: sqlalchemy.select() and tablename.select() why are they different?

2007-09-06 Thread Michael Bayer


On Sep 6, 2007, at 11:28 PM, Lukasz Szybalski wrote:


 Otherwise questions arise:
 which one do i do  filter(), filter_by(), query() select() select_by()
 Is order_by a passed in parameter or function of a filter() or query()
 or is it ?
 Why do I have to specify all()? Shouldn't  that be a default?
 What is the order of functions to call? Which one is used on what?

 What you guys think?


take a look at the ORM and SQL Expression tutorials in the 0.4 docs.   
we've simplified the methods there.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Elixir performance

2007-09-06 Thread EricHolmberg

 I am quite surprised at the results. I would have thought
 ActiveMapper/TurboEntity would only be marginally slower than plain
 SQLAlchemy. And again, I'm surprised that SA is faster than MySQLdb. How
 does that work out? I though SA used MySQLdb??? Your use of query cache
 and best of three sounds sensible, but I've got a feeling we're seeing
 some kind of measurement effect in the results.

I think SA is caching the results of the queries, so it has less
processing to do than MySQLdb for the repeat queries.


 If those numbers are correct though, I'd expect fairly simple changes to
 Elixir could bring the performance close to plain SA.


I think that's a reasonable assumption - I haven't had a chance to
poke around under the hood due to other priorities, but I like Elixir
and hope to see it improve in future versions.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---