[sqlalchemy] Re: dealing with NULLS in 1-many relationships

2016-06-06 Thread Horcle
rList", backref=backref("Provider"), lazy='dynamic') but neither did this. On Monday, June 6, 2016 at 10:46:23 AM UTC-5, Horcle wrote: > > So I can set it to a default value, such as 'N/A' - something similar to > the MSSQL function ISNULL that I can use in the class definition

[sqlalchemy] Re: dealing with NULLS in 1-many relationships

2016-06-06 Thread Horcle
So I can set it to a default value, such as 'N/A' - something similar to the MSSQL function ISNULL that I can use in the class definition. On Monday, June 6, 2016 at 10:41:08 AM UTC-5, Horcle wrote: > > I'm basically looking for something I can add to the backref or ForeignKey > d

[sqlalchemy] Re: dealing with NULLS in 1-many relationships

2016-06-06 Thread Horcle
I'm basically looking for something I can add to the backref or ForeignKey definition for the case that the value of provider_id is None. On Monday, June 6, 2016 at 10:21:39 AM UTC-5, Horcle wrote: > > I have the following models: > > class LabResult(Model): > __tablename__ = 'cp

Re: [sqlalchemy] Re: Dealing with large collections in a scaffolded application

2016-06-06 Thread Horcle
This worked, btw. Thanks! On Wednesday, June 1, 2016 at 5:45:45 PM UTC-5, Horcle wrote: > > Ha! Yes, I should not have taken this literally. Will try tomorrow and let > you know the outcome. > > Thanks! > > On Wednesday, June 1, 2016 at 3:55:35 PM UTC-5, Mike Bayer

[sqlalchemy] dealing with NULLS in 1-many relationships

2016-06-06 Thread Horcle
I have the following models: class LabResult(Model): __tablename__ = 'cp_svc_lab_result' id = Column(Integer, primary_key=True, autoincrement=True) test_code = Column(String(255)) test_code_system = Column(String(255)) test_name = Column(String(255)) test_name_orig = Column(String(255)) proc_name

Re: [sqlalchemy] Re: Dealing with large collections in a scaffolded application

2016-06-01 Thread Horcle
g like that. check the docs. > > > > On 06/01/2016 04:19 PM, Horcle wrote: > > Hi Mike, > > Just verifying: > > > > Should > > > > class Patient(Model): > > encounters = relationship( > > &quo

Re: [sqlalchemy] Re: Dealing with large collections in a scaffolded application

2016-06-01 Thread Horcle
nd > regardless, performance will suffer without an index on this column). > Typically, Encounter.patient_id would refer to the primary key of > Patient which is Patient.id. > > > > On 05/31/2016 04:38 PM, Horcle wrote: > > I guess my question is: How can I effi

Re: [sqlalchemy] Re: Dealing with large collections in a scaffolded application

2016-05-31 Thread Horcle
se backends as a real constraint unless one is added (and > regardless, performance will suffer without an index on this column). > Typically, Encounter.patient_id would refer to the primary key of > Patient which is Patient.id. > > > > On 05/31/2016 04:38 PM, Horcle wrote:

[sqlalchemy] Re: Dealing with large collections in a scaffolded application

2016-05-31 Thread Horcle
fine and access an instance of the Patient object. On Tuesday, May 31, 2016 at 11:20:37 AM UTC-5, Horcle wrote: > > I have the following two models: > > Class Encounter(Model): > __tablename__ = 'cp_service' > id = Column(Integer, primary_key=True,

[sqlalchemy] Dealing with large collections in a scaffolded application

2016-05-31 Thread Horcle
I have the following two models: Class Encounter(Model): __tablename__ = 'cp_service' id = Column(Integer, primary_key=True, autoincrement=True) master_service_id = Column(String(255)) admission_datetime = Column(DateTime) admission_provider_id = Column(String(255))

Re: [sqlalchemy] Padding columns to a query

2016-02-17 Thread Horcle
Works perfectly! Thanks! Greg-- On Wednesday, February 17, 2016 at 11:48:55 AM UTC-6, Simon King wrote: > > On Wed, Feb 17, 2016 at 5:29 PM, Horcle <g...@umn.edu > > wrote: > >> I have the following query db.session.query(label('sid', >> distinct(Clinical.patien

[sqlalchemy] Padding columns to a query

2016-02-17 Thread Horcle
I have the following query db.session.query(label('sid', distinct(Clinical.patient_sid))) to which I would like to pad a few extra columns with constant values, like in the following SQL example select distinct(Clinical.patient_sid) as sid, 'stuph' as attribute from Clinical I tried the

[sqlalchemy] Re: use of replace

2015-12-28 Thread Horcle
Looking for something to mimic the replace function in an SQL statement, like: Select * from Clinical where replace(Clinical.string_value, ' ' , '_') On Monday, December 28, 2015 at 11:49:38 AM UTC-6, Horcle wrote: > > I am iteratively building a complex query. For one step, I have &

[sqlalchemy] Re: use of replace

2015-12-28 Thread Horcle
Looking for something like: Select * from Clinical where replace(Clinical.string_value, ' ', '_') = 'value_here' On Monday, December 28, 2015 at 1:16:36 PM UTC-6, Horcle wrote: > > Or something along the lines of > > Clinical.string_value.replace(' ', '_').op... > > > >

[sqlalchemy] use of replace

2015-12-28 Thread Horcle
I am iteratively building a complex query. For one step, I have a[i] = a[i].filter(Clinical.string_value.op('=')([value[i]])).subquery() I would like to simply just replace the value in Clinical.string value such that all spaces are turned into underscores. My naive approach is to do this as

[sqlalchemy] Re: use of replace

2015-12-28 Thread Horcle
Or something along the lines of Clinical.string_value.replace(' ', '_').op... On Monday, December 28, 2015 at 11:49:38 AM UTC-6, Horcle wrote: > > I am iteratively building a complex query. For one step, I have > > a[i] = a[i].filter(Clinical.string_value.op('=')([value[i]

Re: [sqlalchemy] Re: use of replace

2015-12-28 Thread Horcle
h > just using Python replace on that side, converting from underscore to > space. > > > On 12/28/2015 04:29 PM, Horcle wrote: > > Looking for something to mimic the replace function in an SQL statement, > > like: > > > > Select * from Clinical whe

[sqlalchemy] adjacency list to nested dictionary

2015-12-16 Thread Horcle
I have the following SQLAlchemy class representing an adjacency list: class Node(db.Model): __tablename__ = 'meds' id = Column(Integer, primary_key=True) type = Column(String(64)) name = Column(String(64)) parent_id = Column(Integer, ForeignKey('node.id')) children =

Re: [sqlalchemy] adjacency list to nested dictionary

2015-12-16 Thread Horcle
in your app or use SQLAlchemy to generate > a SQL query that does all the work within the DB and then returns the > result? > > > ᐧ > > On Wed, Dec 16, 2015 at 1:28 PM, Horcle <g...@umn.edu > > wrote: > >> I have the following SQLAlchemy class

Re: [sqlalchemy] Bulk insert using bulk_insert_mappings

2015-12-03 Thread Horcle
Sweet! It was the commit. Thanks! Greg-- On Thursday, December 3, 2015 at 10:48:45 AM UTC-6, Michael Bayer wrote: > > > > On 12/03/2015 11:28 AM, Horcle wrote: > > I am trying to do a bulk insert of a large list of dictionaries of the > form: > > > >

[sqlalchemy] Bulk insert using bulk_insert_mappings

2015-12-03 Thread Horcle
I am trying to do a bulk insert of a large list of dictionaries of the form: results = [{'attribute': u'SEX', 'value_d': 0.0, 'value_s': u'M', 'sid': 1L}, {'attribute': u'SEX', 'value_d': 0.0, 'value_s': u'M', 'sid': 2L}, {'attribute': u'SEX', 'value_d': 0.0,

[sqlalchemy] Expanded view of query parameters

2015-07-09 Thread Horcle
Dear all, How can I expand the output to show ALL query parameters. For example, I have the following: 2015-07-09 09:51:09,478 INFO sqlalchemy.engine.base.Engine (['test_code'], ['13457-7'], ['result_value_num'], '160', '160', ['1970-01-01'], ['blood_pressure'], ['blood_pressure'] ...

[sqlalchemy] Trying to join a session query to a union

2015-07-08 Thread Horcle
Hi all, I have the following union query: q1 = db.session.query(label('sid',distinct(left.c.patient_sid))) q2 = db.session.query(label('sid',distinct(right.c.patient_sid))) query = q1.union_all(q2) Which works just fine. And I have the following query to which I would like to join this:

[sqlalchemy] Re: Trying to join a session query to a union

2015-07-08 Thread Horcle
For the record, this should have a '==' for the join condition: q = intersect.join(query_select, query_select.c.sid == intersect.c.sid) On Wednesday, July 8, 2015 at 7:48:54 PM UTC-5, Horcle wrote: Weird, I had tried using the subquery() method earlier, but it didn't work. Not sure why

[sqlalchemy] Re: Trying to join a session query to a union

2015-07-08 Thread Horcle
Weird, I had tried using the subquery() method earlier, but it didn't work. Not sure why, but now it is returning the desired query object. (I guess stepping away from this for a few hours was a good idea, eh?!) Thanks! Greg-- On Wednesday, July 8, 2015 at 6:24:16 PM UTC-5, Jonathan Vanasco

[sqlalchemy] use of between() with Column.op()

2015-04-10 Thread Horcle
I really dig use of the column operator for constructing queries, but have been unsuccessful with using this when the argument is between. I read somewhere that Column.op(var) when var = in_ does not work, so I would assume that this is true with between. Am I doing something wrong, or is

Re: [sqlalchemy] use of between() with Column.op()

2015-04-10 Thread Horcle
10:23 PM, Horcle wrote: I really dig use of the column operator for constructing queries, but have been unsuccessful with using this when the argument is between. I read somewhere that Column.op(var) when var = in_ does not work, so I would assume that this is true with between

[sqlalchemy] Re: Dynamically constructing joins

2015-03-25 Thread Horcle
eval() was definitely not doing what I expected. Thanks for the tip about getattr(), and thanks for helping get my head screwed on right! Greg-- On Wednesday, March 25, 2015 at 11:33:44 AM UTC-5, Jonathan Vanasco wrote: Yeah, there's no reason to touch eval -- and a lot of reasons not to.

[sqlalchemy] Dynamically constructing joins

2015-03-24 Thread Horcle
I have a situation where I can have an arbitrary number of subqueries that need to be joined on the last step, except if the number of queries, n, is 1. For example, for n = 1, suppose I have a complex query set to the variable A[1] The final submitted query would then look like:

Re: [sqlalchemy] Issue with return results

2014-09-08 Thread Horcle
-bit python now, so this makes sense. Thanks! Greg-- On Thursday, September 4, 2014 9:20:53 PM UTC-5, Horcle wrote: I think I am going to dump SQL Server and just go with Postgres. Much easier, and less of a headache. Fortunately, we are not yet in production. Thanks! Greg-- Thanks. I

[sqlalchemy] Issue with return results

2014-09-04 Thread Horcle
I had to reinstall my python dev environment from scratch due to a hd failure, and in the process something seems to have changed. When querying against MS SQL using the script (test_conenction.py): import pyodbc import sqlalchemy from sqlalchemy.engine import reflection from

Re: [sqlalchemy] Issue with return results

2014-09-04 Thread Horcle
The first place I’d look in this case would be your freetds.conf, you probably need to configure the character set correctly in there. On Sep 4, 2014, at 5:06 PM, Horcle g...@umn.edu javascript: wrote: I had to reinstall my python dev environment from scratch due to a hd failure

Re: [sqlalchemy] cannot access tables

2014-08-18 Thread Horcle
On Friday, August 15, 2014 8:28:41 PM UTC-5, Michael Bayer wrote: On Aug 15, 2014, at 5:03 PM, Greg Silverman g...@umn.edu javascript: wrote: Then, I thought, what if this is an SQLAlchemy issue. Looks to be. I ran the following script as a test: import pyodbc import sqlalchemy from

Re: [sqlalchemy] cannot access tables

2014-08-18 Thread Horcle
sqlalchemy.engine.base.Engine Col ('TABLE_NAME',) A Not quite sure how to parse this? For example, is u'dbo' what is being used as the schema? Greg-- On Monday, August 18, 2014 10:05:09 AM UTC-5, Simon King wrote: On Mon, Aug 18, 2014 at 3:47 PM, Horcle g...@umn.edu javascript: wrote

Re: [sqlalchemy] cannot access tables

2014-08-18 Thread Horcle
about MS-SQL so can't tell you why that is, but perhaps you've got enough information to carry on digging? Hope that helps, Simon On Mon, Aug 18, 2014 at 4:27 PM, Horcle g...@umn.edu javascript: wrote: Indeed! Here is the output: gms$ python test_connect.py 2014-08

Re: [sqlalchemy] cannot access tables

2014-08-18 Thread Horcle
, Aug 18, 2014 at 5:22 PM, Horcle g...@umn.edu javascript: wrote: Thanks, this does help. I was wondering why the return results had no values given. Greg-- On Monday, August 18, 2014 11:17:48 AM UTC-5, Simon King wrote: I think you are seeing, for each query: 1

Re: [sqlalchemy] cannot access tables

2014-08-18 Thread Horcle
(); cursor.execute(the statement); cursor.fetchall()). the way pyodbc is connecting might be changing things. On Aug 18, 2014, at 12:59 PM, Horcle g...@umn.edu javascript: wrote: Thanks for the heads up. Unfortunately, it did not help. In any case, the issue appears to be that while the last query