[sqlalchemy] Querying few related tables with limiting subqueries and filtering by keyword (Pyramid and SQLAlchemy)

2014-08-27 Thread Ljós Berinn
Hi! I have defined my models in Pyramid like this: # coding: utf-8 from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Integer, Float, DateTime, ForeignKey, ForeignKeyConstraint, String, Column from sqlalchemy.orm import scoped_session, sessionmaker, relationship,

[sqlalchemy] Getting Subquery with labels in SQLAlchemy 0.7.4 to Work

2014-08-27 Thread Anthony Phan Le
I am trying to convert the following SQL statement into an Sqlalchemy ORM (Version 0.7.4) statement: SELECT [hermes_stage].[dbo].[run].[tank] ,[id] ,[experiment_id] ,[local_id] ,[start_time] ,[stop_time] FROM [some_db].[run] INNER JOIN ( Select

[sqlalchemy] How do I perform a join on a subquery properly in SQLAlchemy?

2014-08-27 Thread Anthony Le
I have a sqlalchemy query using a subquery listed below: test = model.session.query(func.max(SomeEntity.start_time), SomeEntity.name).filter(Run.name.in_(['some name'])).group_by(SomeEntity.name).with_labels().subquery(name = 'sub') SomeEntity.query().join(test,

[sqlalchemy] How do I join a subquery using labels for columns that represent aggregate functions?

2014-08-27 Thread Anthony Le
Sorry for the multiple attempts at posting. I am not sure if posts are time delayed but I am not seeing what I thought I posted. So I am trying one more time. I am trying to convert the following SQL statement into an Sqlalchemy ORM (Version 0.7.4) statement: SELECT

[sqlalchemy] Getting Subquery with labels in SQLAlchemy 0.7.4 to Work

2014-08-27 Thread Anthony Le
I am trying to convert the following SQL statement into an Sqlalchemy ORM (Version 0.7.4) statement: SELECT [hermes_stage].[dbo].[run].[tank] ,[id] ,[experiment_id] ,[local_id] ,[start_time] ,[stop_time] FROM [some_db].[run] INNER JOIN (

Re: [sqlalchemy] generating alter table statements for foreign key constraints by default

2014-08-27 Thread Michael Bayer
you can alter how MetaData things are built up using the after_parent_attach event: http://docs.sqlalchemy.org/en/rel_0_9/core/events.html?highlight=after_parent_attach#sqlalchemy.events.DDLEvents.after_parent_attach apply the event to ForeignKey and set use_alter=True for all of them as they

[sqlalchemy] Not able to pass Non-ASCII strings as a filter to raw sql select statement

2014-08-27 Thread pravin battula
Hi, When i pass a Non-ASCII string in where condition filter of an raw SQL statement, the SQLALCHEMY showing below error during an execution of query File /base/data/home/apps/s~ipaddress/versionnumber/flow/services/requestExport.py, line 119, in getRecordsFromDB instanceList =

Re: [sqlalchemy] generating alter table statements for foreign key constraints by default

2014-08-27 Thread Bala Ramakrishnan
Thanks for the reply. I had implemented this feature about two months ago, and I had forgotten myself. I had originally used this: def rand_hex_str(): return '%016x' % random.getrandbits(64) # using event listener to force foreign key definitions to use 'alter statements' def

Re: [sqlalchemy] generating alter table statements for foreign key constraints by default

2014-08-27 Thread Michael Bayer
On Aug 27, 2014, at 3:38 PM, Bala Ramakrishnan bal...@gmail.com wrote: Thanks for the reply. I had implemented this feature about two months ago, and I had forgotten myself. I had originally used this: def rand_hex_str(): return '%016x' % random.getrandbits(64) # using event

Re: [sqlalchemy] after_flush_postexec event: finding all instances that were inserted

2014-08-27 Thread Chad Dombrova
Thanks for the quick response Michael. One more question, if you don't mind: I updated my gist to demonstrate this problem: https://gist.github.com/chadrik/08617b6ed4d9cbacd93c To sum it up, I added a one-to-many relationships between Books and Chapters, but the relationships which show items

Re: [sqlalchemy] after_flush_postexec event: finding all instances that were inserted

2014-08-27 Thread Michael Bayer
On Aug 27, 2014, at 5:31 PM, Chad Dombrova chad...@gmail.com wrote: Thanks for the quick response Michael. One more question, if you don't mind: I updated my gist to demonstrate this problem: https://gist.github.com/chadrik/08617b6ed4d9cbacd93c To sum it up, I added a one-to-many

[sqlalchemy] Creating a new instance using an identity key/pk?

2014-08-27 Thread Gerald Thibault
I have a pretty simple goal, so simple I probably don't even need example code. I have 2 classes, and I want to pull the identity key from an instance of one class, and use the values to create an instance of the second, without requiring (or introspecting) things like the PK names, FK names

Re: [sqlalchemy] Creating a new instance using an identity key/pk?

2014-08-27 Thread Michael Bayer
On Aug 27, 2014, at 6:17 PM, Gerald Thibault dieselmach...@gmail.com wrote: I have a pretty simple goal, so simple I probably don't even need example code. I have 2 classes, and I want to pull the identity key from an instance of one class, and use the values to create an instance of the

Re: [sqlalchemy] Creating a new instance using an identity key/pk?

2014-08-27 Thread Gerald Thibault
On Wednesday, August 27, 2014 4:58:50 PM UTC-7, Michael Bayer wrote: On Aug 27, 2014, at 6:17 PM, Gerald Thibault diesel...@gmail.com javascript: wrote: I have a pretty simple goal, so simple I probably don't even need example code. I have 2 classes, and I want to pull the

Re: [sqlalchemy] Creating a new instance using an identity key/pk?

2014-08-27 Thread Gerald Thibault
Also, this might help to clarify my goal, this is my current working code that accomplishes the desired result, but with more introspection than I was hoping for. If there isn't something easier, this will work. # instance1 is an instance of Class1, i want to create Class2 with the same pk