Re: [sqlalchemy] How to format class property as another accessible property

2017-06-07 Thread Greg Silverman
Oh right, I've used the @property decorator before, just been a while.

Thanks for the explanation of @hybrid_property. Makes sense.

On Wed, Jun 7, 2017 at 5:32 PM, mike bayer <mike...@zzzcomputing.com> wrote:

>
>
> On 06/07/2017 06:19 PM, Greg Silverman wrote:
>
>> Thanks, it worked!
>>
>> I tried something similar using the @hybrid_property decorator, but could
>> not get it to work. What exactly is the difference between that and the
>> @property decorator?
>>
>
>
> @property is super normal Python stuff that's in all the Python tutorials
> and is something everyone should use all the time.
>
> @hybrid_property is more of a magic trick that's specific to the kind of
> query interface that SQLAlchemy has - in that in an ORM like SQLAlchemy
> (and lots of others), you access attributes off of classes, as well as
> instances of those classes, as part of regular use of the API.  This is not
> a standard object-oriented thing, it's kind of odd.   The @hybrid_property
> allows you to build functions that act a lot like @property, but they
> accommodate for accessing an attribute both at the "instance" (e.g. 'self')
> level and at the "class" level.   Which translated to SQLAlchemy means, at
> the "row I've loaded into memory" level and the "SQL expression I want to
> execute on the database" level.  The kinds of functions we can use in these
> two very different contexts are quite different.
>
>
>
>
>
>
>
>> Greg--
>>
>>
>> On Wed, Jun 7, 2017 at 5:08 PM, mike bayer <mike...@zzzcomputing.com
>> <mailto:mike...@zzzcomputing.com>> wrote:
>>
>>
>>
>> On 06/07/2017 02:31 PM, GMS wrote:
>>
>> I am sure this is easier than I am making it, but I just want to
>> add a property to a class so that decimal representations get
>> truncated at 3 decimal digits.
>>
>> My class is this:
>>
>> class Measures(Model):
>> __tablename__= 'xcelera_measures'
>> id= Column(Numeric,primary_key=True)
>>   studyidk= Column(Numeric, ForeignKey('xcel.studyidk'))
>>  xceleragroup= relationship("Xcelera")
>>   explainstring= Column(String(255))
>>   mrn= Column(String(255))
>>   value= Column(Numeric)
>>
>>   __mapper_args__= {
>>   "order_by": [mrn]
>>   }
>>
>>
>> and 'value' is the property/attribute that I want to also have a
>> truncated version available in the class.
>>
>> I tried adding this to the class value_new =
>> column_property("%.3f" % value())
>>
>> but got an error that
>>
>> value_new = column_property("%.3f" % value)
>>
>>
>> "%" is a Python function, that doesn't execute on the database.
>>  This works as a normal Python descriptor:
>>
>> class MyClass(Base):
>>  # ...
>>
>>  @property
>>  def value_new(self):
>>  return "%.3f" % self.value
>>
>>
>>
>>
>>
>>
>>
>>
>> TypeError: float argument required, not Column
>>
>> I also tried this as a hybrid_property, but I don't think I was
>> using it correctly.
>>
>> All I want to do is have the truncated version of my attribute
>> available in my class.
>>
>> Thanks!
>>
>> Greg--
>>
>>
>> -- SQLAlchemy -
>> The Python SQL Toolkit and Object Relational Mapper
>>
>> http://www.sqlalchemy.org/
>>
>> To post example code, please provide an MCVE: Minimal, Complete,
>> and Verifiable Example. See http://stackoverflow.com/help/mcve
>> <http://stackoverflow.com/help/mcve> for a full description.
>> ---
>> You received this message because you are subscribed to the
>> Google Groups "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from
>> it, send an email to sqlalchemy+unsubscr...@googlegroups.com
>> <mailto:sqlalchemy%2bunsubscr...@googlegroups.com>
>> <mailto:sqlalchemy+unsubscr...@googlegroups.com
>> <mailto:sqlalchemy%2bunsubscr...@googlegroups.com>>.
>> To post to this group, send email to sqlalchemy@googlegroups.com
>>   

Re: [sqlalchemy] How to format class property as another accessible property

2017-06-07 Thread Greg Silverman
Thanks, it worked!

I tried something similar using the @hybrid_property decorator, but could
not get it to work. What exactly is the difference between that and the
@property decorator?

Greg--

On Wed, Jun 7, 2017 at 5:08 PM, mike bayer  wrote:

>
>
> On 06/07/2017 02:31 PM, GMS wrote:
>
>> I am sure this is easier than I am making it, but I just want to add a
>> property to a class so that decimal representations get truncated at 3
>> decimal digits.
>>
>> My class is this:
>>
>> class Measures(Model):
>> __tablename__= 'xcelera_measures'
>> id= Column(Numeric,primary_key=True)
>>  studyidk= Column(Numeric, ForeignKey('xcel.studyidk'))
>> xceleragroup= relationship("Xcelera")
>>  explainstring= Column(String(255))
>>  mrn= Column(String(255))
>>  value= Column(Numeric)
>>
>>  __mapper_args__= {
>>  "order_by": [mrn]
>>  }
>>
>>
>> and 'value' is the property/attribute that I want to also have a
>> truncated version available in the class.
>>
>> I tried adding this to the class value_new = column_property("%.3f" %
>> value())
>>
>> but got an error that
>>
>> value_new = column_property("%.3f" % value)
>>
>
> "%" is a Python function, that doesn't execute on the database.  This
> works as a normal Python descriptor:
>
> class MyClass(Base):
> # ...
>
> @property
> def value_new(self):
> return "%.3f" % self.value
>
>
>
>
>
>
>
>
>> TypeError: float argument required, not Column
>>
>> I also tried this as a hybrid_property, but I don't think I was using it
>> correctly.
>>
>> All I want to do is have the truncated version of my attribute available
>> in my class.
>>
>> Thanks!
>>
>> Greg--
>>
>>
>> --
>> SQLAlchemy -
>> The Python SQL Toolkit and Object Relational Mapper
>>
>> http://www.sqlalchemy.org/
>>
>> To post example code, please provide an MCVE: Minimal, Complete, and
>> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
>> description.
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to sqlalchemy+unsubscr...@googlegroups.com > sqlalchemy+unsubscr...@googlegroups.com>.
>> To post to this group, send email to sqlalchemy@googlegroups.com > sqlalchemy@googlegroups.com>.
>> Visit this group at https://groups.google.com/group/sqlalchemy.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example.  See  http://stackoverflow.com/help/mcve for a full
> description.
> --- You received this message because you are subscribed to a topic in the
> Google Groups "sqlalchemy" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/to
> pic/sqlalchemy/3FFm1stwEoU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Greg M. Silverman

 ›  flora-script  ‹
 ›  grenzi.org  ›

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: How to format class property as another accessible property

2017-06-07 Thread Greg Silverman
Hi,
Thanks for pointing that out. It's still throwing the same error, even when
changed. Does not seem to like passing the column name to the
column_property method.

Greg--



On Wed, Jun 7, 2017 at 3:30 PM, Jonathan Vanasco 
wrote:

> These are two different lines of code.  The second one looks correct.
>
>> value_new = column_property("%.3f" % value())
>> value_new = column_property("%.3f" % value)
>>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "sqlalchemy" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/sqlalchemy/3FFm1stwEoU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Greg M. Silverman

 ›  flora-script  ‹
 ›  grenzi.org  ›

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Grouped data in a Flask/SQLAlchemy class

2017-04-24 Thread Greg Silverman
Yes, I can certainly do that. Sounds pretty simple, actually. I may have
more questions as I dive into this.

Thanks!




On Mon, Apr 24, 2017 at 3:06 PM, mike bayer <mike...@zzzcomputing.com>
wrote:

>
>
> On 04/24/2017 03:42 PM, Greg Silverman wrote:
>
>> My naive first response would be that I want the class to look like
>>
>> class DiagnosisTest(Model):
>> __tablename__= 'vw_svc_diagnosis'
>> #id = Column(Integer, primary_key=True, autoincrement=True)
>> dx_id= Column(String(32),primary_key=True)
>>  first_name= Column(String(255))
>>  last_name= Column(String(255))
>>  mrn= Column(String(255))
>>  dx_code= Column(String(255))
>>  #dx_code_orig = Column(String(255))
>> dx_code_type= Column(String(255))
>>  dx_name= Column(String(255))
>>  #chronic_diagnosis_yn = Column(String(255))
>> diagnosis_datetime= Column(DateTime)
>>
>>
>>
>>  @property
>> def get_diagnosis_groups(self):
>>
>> import itertoolsas itertools
>>
>>  for (dx_code, patient_id), detailsin itertools.groupby(self,
>> keyfunc):
>> diagnosis_group  = DiagnosisGroup(
>>  dx_code, patient_id
>>  )
>>  diagnosis_group.details= details
>>  for detailin details:
>> detail.group= diagnosis_group
>>  yield diagnosis_group
>>
>>
>> So that I could then instantiate this and access grouped elements like
>> DiagnosisTest.get_diagnosis_groups.patient_id and
>> DiagnosisTest.get_diagnosis_groups.dx_code for example.
>>
>
>
> OK can you add a relationship() to DiagnosisTest that returns a list of
> DiagnosisDetail objects?  that would be all you need here.
>
>
>
>
>> I am sure this does not answer your question, but what I really want to
>> do is have the data grouped within the class and available whenever I
>> instantiate the class.
>>
>> I know what I need, but I am having problems in articulating the details.
>>
>> Thanks for being patient with me! ^_^
>>
>>
>> On Mon, Apr 24, 2017 at 12:21 PM, mike bayer <mike...@zzzcomputing.com
>> <mailto:mike...@zzzcomputing.com>> wrote:
>>
>>
>>
>> On 04/24/2017 12:51 PM, Greg Silverman wrote:
>>
>> Hi Mike,
>> I'm finally getting to this.  Instead of having both a detail
>> and grouped methods, I would like to have only the grouped
>> method. I'm not sure I follow your suggestion for the two
>> methods above and how that would be modified to fit into the
>> @property in my class.
>>
>> Could you please elaborate a bit how these would work within
>> context of the class?
>>
>>
>> cutting and pasting:
>>
>>
>>def get_diagnosis_groups(sorted_list_of_diagnosis_detail):
>>
>>  for (dx_code, patient_id), details in
>> itertools.groupby(sorted_list_of_diagnosisdetail, keyfunc):
>>  diagnosis_group = DiagnosisGroup(
>> dx_code, patient_id
>>  )
>>  diagnosis_group.details = details
>>  for detail in details:
>>  detail.group = diagnosis_group
>>  yield diagnosis_group
>>
>>
>> you want to take out the "sorted_list_of_diagnosis_detail" argument.
>> OKbut I don't know where you'd like to get this from.  Where is
>> this "method" going and are you calling that as a classmethod or an
>> instance method?  what class?   Just show a usage example.
>>
>>
>>
>>
>>
>>
>>
>> Thanks!
>>
>> Greg--
>>
>>
>>
>>
>> On Wed, Mar 1, 2017 at 8:53 PM, mike bayer
>> <mike...@zzzcomputing.com <mailto:mike...@zzzcomputing.com>
>> <mailto:mike...@zzzcomputing.com
>>
>> <mailto:mike...@zzzcomputing.com>>> wrote:
>>
>>
>>
>>  On 03/01/2017 08:27 PM, GMS wrote:
>>
>>  I have the following class models:
>>
>>
>>  |  class DiagnosisDetail(Model):
>>   __tablename__ = 'vw_svc_diagnosis'
>>   diagnosis_id = Column(String(32),
>> primary_key=True)
>>   first_name = Column(String(255))
>>   last_name = Column(String(

Re: [sqlalchemy] Grouped data in a Flask/SQLAlchemy class

2017-04-24 Thread Greg Silverman
My naive first response would be that I want the class to look like

class DiagnosisTest(Model):
__tablename__ = 'vw_svc_diagnosis'
#id = Column(Integer, primary_key=True, autoincrement=True)
dx_id = Column(String(32), primary_key=True)
first_name = Column(String(255))
last_name = Column(String(255))
mrn = Column(String(255))
dx_code = Column(String(255))
#dx_code_orig = Column(String(255))
dx_code_type = Column(String(255))
dx_name = Column(String(255))
#chronic_diagnosis_yn = Column(String(255))
diagnosis_datetime = Column(DateTime)



@property
def get_diagnosis_groups(self):

import itertools as itertools

for (dx_code, patient_id), details in itertools.groupby(self, keyfunc):
diagnosis_group = DiagnosisGroup(
dx_code, patient_id
)
diagnosis_group.details = details
for detail in details:
detail.group = diagnosis_group
yield diagnosis_group


So that I could then instantiate this and access grouped elements like
DiagnosisTest.get_diagnosis_groups.patient_id and
DiagnosisTest.get_diagnosis_groups.dx_code for example.

I am sure this does not answer your question, but what I really want to do
is have the data grouped within the class and available whenever I
instantiate the class.

I know what I need, but I am having problems in articulating the details.

Thanks for being patient with me! ^_^


On Mon, Apr 24, 2017 at 12:21 PM, mike bayer <mike...@zzzcomputing.com>
wrote:

>
>
> On 04/24/2017 12:51 PM, Greg Silverman wrote:
>
>> Hi Mike,
>> I'm finally getting to this.  Instead of having both a detail and grouped
>> methods, I would like to have only the grouped method. I'm not sure I
>> follow your suggestion for the two methods above and how that would be
>> modified to fit into the @property in my class.
>>
>> Could you please elaborate a bit how these would work within context of
>> the class?
>>
>
> cutting and pasting:
>
>
>   def get_diagnosis_groups(sorted_list_of_diagnosis_detail):
>
> for (dx_code, patient_id), details in
> itertools.groupby(sorted_list_of_diagnosisdetail, keyfunc):
> diagnosis_group = DiagnosisGroup(
>dx_code, patient_id
> )
> diagnosis_group.details = details
> for detail in details:
> detail.group = diagnosis_group
> yield diagnosis_group
>
>
> you want to take out the "sorted_list_of_diagnosis_detail" argument.
> OKbut I don't know where you'd like to get this from.  Where is this
> "method" going and are you calling that as a classmethod or an instance
> method?  what class?   Just show a usage example.
>
>
>
>
>
>
>
>> Thanks!
>>
>> Greg--
>>
>>
>>
>>
>> On Wed, Mar 1, 2017 at 8:53 PM, mike bayer <mike...@zzzcomputing.com
>> <mailto:mike...@zzzcomputing.com>> wrote:
>>
>>
>>
>> On 03/01/2017 08:27 PM, GMS wrote:
>>
>> I have the following class models:
>>
>>
>> |  class DiagnosisDetail(Model):
>>  __tablename__ = 'vw_svc_diagnosis'
>>  diagnosis_id = Column(String(32), primary_key=True)
>>  first_name = Column(String(255))
>>  last_name = Column(String(255))
>>  mrn = Column(String(255))
>>  dx_code = Column(String(255))
>>  dx_id = Column(String(255), ForeignKey('dx_group.dx_id'))
>>  diagnosisgroup = relationship("DiagnosisGroup")
>>  dx_code_type = Column(String(255))
>>  dx_name = Column(String(255))
>>
>>  __mapper_args__ = {
>>   "order_by":[mrn, dx_name]
>> }
>>
>>  class DiagnosisGroup(Model):
>>  __tablename__ = 'diagnosis_group'
>>  dx_id = Column(String(32), primary_key=True)
>>  mrn = Column(String(255))
>>  dx_code = Column(String(255))
>>  dx_code_type = Column(String(255))
>>  dx_name = Column(String(255))
>>  diagnosis_datetime = Column(DateTime)
>>
>>  __mapper_args__ = {
>>   "order_by":[mrn, dx_name]
>> }|
>>
>>
>>
>> where the underlying tables for DiagnosisGroup and
>> DiagnosisDetail are
>> SQL views. DiagnosisGroup is so that I can have a more succi

Re: [sqlalchemy] Grouped data in a Flask/SQLAlchemy class

2017-04-24 Thread Greg Silverman
Hi Mike,
I'm finally getting to this.  Instead of having both a detail and grouped
methods, I would like to have only the grouped method. I'm not sure I
follow your suggestion for the two methods above and how that would be
modified to fit into the @property in my class.

Could you please elaborate a bit how these would work within context of the
class?

Thanks!

Greg--



On Wed, Mar 1, 2017 at 8:53 PM, mike bayer  wrote:

>
>
> On 03/01/2017 08:27 PM, GMS wrote:
>
>> I have the following class models:
>>
>>
>> |  class DiagnosisDetail(Model):
>> __tablename__ = 'vw_svc_diagnosis'
>> diagnosis_id = Column(String(32), primary_key=True)
>> first_name = Column(String(255))
>> last_name = Column(String(255))
>> mrn = Column(String(255))
>> dx_code = Column(String(255))
>> dx_id = Column(String(255), ForeignKey('dx_group.dx_id'))
>> diagnosisgroup = relationship("DiagnosisGroup")
>> dx_code_type = Column(String(255))
>> dx_name = Column(String(255))
>>
>> __mapper_args__ = {
>>  "order_by":[mrn, dx_name]
>>}
>>
>> class DiagnosisGroup(Model):
>> __tablename__ = 'diagnosis_group'
>> dx_id = Column(String(32), primary_key=True)
>> mrn = Column(String(255))
>> dx_code = Column(String(255))
>> dx_code_type = Column(String(255))
>> dx_name = Column(String(255))
>> diagnosis_datetime = Column(DateTime)
>>
>> __mapper_args__ = {
>>  "order_by":[mrn, dx_name]
>>}|
>>
>>
>>
>> where the underlying tables for DiagnosisGroup and DiagnosisDetail are
>> SQL views. DiagnosisGroup is so that I can have a more succinct view of
>> the data, since a patient can have the same diagnosis many times. I am
>> wondering if there is a way to do this within the class structure
>>  instead of at the db server?
>>
>
> do you mean, derive a DiagnosisGroup object from a DiagnosisDetail without
> running SQL? (or a list of them?)  (the answer is..sure?  just build Python
> code to generate objects from a list of DiagnosisDetail objects).
>
> I do not wish to do this through any ORM
>
>> session queries, since these two classes have distinct use cases where
>> they bind to wtform views. Thus, I would like to inherit the properties
>> of these two classes from another distinct class.
>>
>> I have not been able to find anything like this, short
>> of [create-column-properties-that-use-a-groupby][1]
>> > e-column-properties-that-use-a-groupby/25879453>,
>> but this uses session queries to achieve the result. I would like to
>> keep everything within the class itself through inheritance of the
>> DiagnosisDetail class.
>>
>
> You don't need a relational database to do grouping, if you have a list of
> data in memory it can be grouped using sets, or most succinctly Python's
> own groupby function: https://docs.python.org/2/libr
> ary/itertools.html#itertools.groupby
>
>
>
>
>> Note: the primary key for DiagnosisGroup, is a concatenation of dx_code
>> and another field patient_id. Groupings thus are unique.
>>
>
> OK, so
>
> def keyfunc(detail):
> return (detail.dx_code, detail.patient_id)
>
> def get_diagnosis_groups(sorted_list_of_diagnosis_detail):
>
> for (dx_code, patient_id), details in
> itertools.groupby(sorted_list_of_diagnosisdetail, keyfunc):
> diagnosis_group = DiagnosisGroup(
>dx_code, patient_id
> )
> diagnosis_group.details = details
> for detail in details:
> detail.group = diagnosis_group
> yield diagnosis_group
>
>
>
>
> I do also need
>
>> the FK relation back to the DiagnosisDetail class, which leads me to
>> believe there should be three classes, where the two above classes
>> inherit their properties from a parent class.
>>
>
>
>
>
>
>> --
>> SQLAlchemy -
>> The Python SQL Toolkit and Object Relational Mapper
>>
>> http://www.sqlalchemy.org/
>>
>> To post example code, please provide an MCVE: Minimal, Complete, and
>> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
>> description.
>> ---
>> You received this message because you are subscribed to the Google
>> Groups "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send
>> an email to sqlalchemy+unsubscr...@googlegroups.com
>> .
>> To post to this group, send email to sqlalchemy@googlegroups.com
>> .
>> Visit this group at https://groups.google.com/group/sqlalchemy.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example.  See  

Re: [sqlalchemy] Grouped data in a Flask/SQLAlchemy class

2017-03-02 Thread Greg Silverman
Mike,
I'll try it and let you know the outcome (it may be a bit before I get to
it, but I like your suggestions much better than having to use SQL views,
which I am only doing due to a time crunch).

Much appreciated!

On Wed, Mar 1, 2017 at 9:52 PM, mike bayer <mike...@zzzcomputing.com> wrote:

>
>
> On 03/01/2017 10:22 PM, Greg Silverman wrote:
>
>>
>>
>> On Wed, Mar 1, 2017 at 8:53 PM, mike bayer <mike...@zzzcomputing.com
>> <mailto:mike...@zzzcomputing.com>> wrote:
>>
>>
>>
>> On 03/01/2017 08:27 PM, GMS wrote:
>>
>> I have the following class models:
>>
>>
>> |  class DiagnosisDetail(Model):
>> __tablename__ = 'vw_svc_diagnosis'
>> diagnosis_id = Column(String(32), primary_key=True)
>> first_name = Column(String(255))
>> last_name = Column(String(255))
>> mrn = Column(String(255))
>> dx_code = Column(String(255))
>> dx_id = Column(String(255), ForeignKey('dx_group.dx_id'))
>> diagnosisgroup = relationship("DiagnosisGroup")
>> dx_code_type = Column(String(255))
>> dx_name = Column(String(255))
>>
>> __mapper_args__ = {
>>  "order_by":[mrn, dx_name]
>>}
>>
>> class DiagnosisGroup(Model):
>> __tablename__ = 'diagnosis_group'
>> dx_id = Column(String(32), primary_key=True)
>> mrn = Column(String(255))
>> dx_code = Column(String(255))
>> dx_code_type = Column(String(255))
>> dx_name = Column(String(255))
>> diagnosis_datetime = Column(DateTime)
>>
>> __mapper_args__ = {
>>  "order_by":[mrn, dx_name]
>>}|
>>
>>
>>
>> where the underlying tables for DiagnosisGroup and
>> DiagnosisDetail are
>> SQL views. DiagnosisGroup is so that I can have a more succinct
>> view of
>> the data, since a patient can have the same diagnosis many
>> times. I am
>> wondering if there is a way to do this within the class structure
>>  instead of at the db server?
>>
>>
>> do you mean, derive a DiagnosisGroup object from a DiagnosisDetail
>> without running SQL?
>>
>>
>>
>> In as much as having the ORM do the work versus the backend, I guess.
>>
>>
>>
>> (or a list of them?)  (the answer is..sure?  just build Python code
>> to generate objects from a list of DiagnosisDetail objects).
>>
>>
>>
>>
>> Hmmm... but I don't get all the benefits of related data/data
>> associations via key constraints that way with a non SQLA object. For
>> example, I have a form that binds the Grouped records to their Detailed
>> records in another form utilizing the one-to-many relationship between
>> the two classes.
>>
>
>
> my example illustrates joining the two types of objects together in the
> same way as a relationship-bound collection would.
>
>
>
>>
>>
>>
>> I do not wish to do this through any ORM
>>
>> session queries, since these two classes have distinct use cases
>> where
>> they bind to wtform views. Thus, I would like to inherit the
>> properties
>> of these two classes from another distinct class.
>>
>> I have not been able to find anything like this, short
>> of [create-column-properties-that-use-a-groupby][1]
>> <http://stackoverflow.com/questions/25822393/how-can-i-creat
>> e-column-properties-that-use-a-groupby/25879453
>> <http://stackoverflow.com/questions/25822393/how-can-i-creat
>> e-column-properties-that-use-a-groupby/25879453>>,
>> but this uses session queries to achieve the result. I would like
>> to
>> keep everything within the class itself through inheritance of the
>> DiagnosisDetail class.
>>
>>
>> You don't need a relational database to do grouping, if you have a
>> list of data in memory it can be grouped using sets, or most
>> succinctly Python's own groupby function:
>> https://docs.python.org/2/library/itertools.html#itertools.groupby
>> <https://docs.python.org/2/library/itertools.html#ite

Re: [sqlalchemy] Grouped data in a Flask/SQLAlchemy class

2017-03-01 Thread Greg Silverman
On Wed, Mar 1, 2017 at 8:53 PM, mike bayer  wrote:

>
>
> On 03/01/2017 08:27 PM, GMS wrote:
>
>> I have the following class models:
>>
>>
>> |  class DiagnosisDetail(Model):
>> __tablename__ = 'vw_svc_diagnosis'
>> diagnosis_id = Column(String(32), primary_key=True)
>> first_name = Column(String(255))
>> last_name = Column(String(255))
>> mrn = Column(String(255))
>> dx_code = Column(String(255))
>> dx_id = Column(String(255), ForeignKey('dx_group.dx_id'))
>> diagnosisgroup = relationship("DiagnosisGroup")
>> dx_code_type = Column(String(255))
>> dx_name = Column(String(255))
>>
>> __mapper_args__ = {
>>  "order_by":[mrn, dx_name]
>>}
>>
>> class DiagnosisGroup(Model):
>> __tablename__ = 'diagnosis_group'
>> dx_id = Column(String(32), primary_key=True)
>> mrn = Column(String(255))
>> dx_code = Column(String(255))
>> dx_code_type = Column(String(255))
>> dx_name = Column(String(255))
>> diagnosis_datetime = Column(DateTime)
>>
>> __mapper_args__ = {
>>  "order_by":[mrn, dx_name]
>>}|
>>
>>
>>
>> where the underlying tables for DiagnosisGroup and DiagnosisDetail are
>> SQL views. DiagnosisGroup is so that I can have a more succinct view of
>> the data, since a patient can have the same diagnosis many times. I am
>> wondering if there is a way to do this within the class structure
>>  instead of at the db server?
>>
>
> do you mean, derive a DiagnosisGroup object from a DiagnosisDetail without
> running SQL?



In as much as having the ORM do the work versus the backend, I guess.



> (or a list of them?)  (the answer is..sure?  just build Python code to
> generate objects from a list of DiagnosisDetail objects).
>



Hmmm... but I don't get all the benefits of related data/data associations
via key constraints that way with a non SQLA object. For example, I have a
form that binds the Grouped records to their Detailed records in another
form utilizing the one-to-many relationship between the two classes.



>
> I do not wish to do this through any ORM
>
>> session queries, since these two classes have distinct use cases where
>> they bind to wtform views. Thus, I would like to inherit the properties
>> of these two classes from another distinct class.
>>
>> I have not been able to find anything like this, short
>> of [create-column-properties-that-use-a-groupby][1]
>> > e-column-properties-that-use-a-groupby/25879453>,
>> but this uses session queries to achieve the result. I would like to
>> keep everything within the class itself through inheritance of the
>> DiagnosisDetail class.
>>
>
> You don't need a relational database to do grouping, if you have a list of
> data in memory it can be grouped using sets, or most succinctly Python's
> own groupby function: https://docs.python.org/2/libr
> ary/itertools.html#itertools.groupby




Indeed. I have used this for other things, but never thought of it for this
case.




>
>
>
>
>
>> Note: the primary key for DiagnosisGroup, is a concatenation of dx_code
>> and another field patient_id. Groupings thus are unique.
>>
>
> OK, so
>
> def keyfunc(detail):
> return (detail.dx_code, detail.patient_id)
>
> def get_diagnosis_groups(sorted_list_of_diagnosis_detail):
>
> for (dx_code, patient_id), details in
> itertools.groupby(sorted_list_of_diagnosisdetail, keyfunc):
> diagnosis_group = DiagnosisGroup(
>dx_code, patient_id
> )
> diagnosis_group.details = details
> for detail in details:
> detail.group = diagnosis_group
> yield diagnosis_group
>



Is there a way to use these as methods within a class model using the
mapper, like in the stackoverflow link I gave?

Thanks for the out-of-the-box approach to thinking about this.

Greg--



>
>
>
> I do also need
>
>> the FK relation back to the DiagnosisDetail class, which leads me to
>> believe there should be three classes, where the two above classes
>> inherit their properties from a parent class.
>>
>
>
>
>
>
>> --
>> SQLAlchemy -
>> The Python SQL Toolkit and Object Relational Mapper
>>
>> http://www.sqlalchemy.org/
>>
>> To post example code, please provide an MCVE: Minimal, Complete, and
>> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
>> description.
>> ---
>> You received this message because you are subscribed to the Google
>> Groups "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send
>> an email to sqlalchemy+unsubscr...@googlegroups.com
>> .
>> To post to this group, send email to sqlalchemy@googlegroups.com
>> .
>> Visit this group at 

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

2016-06-06 Thread Greg Silverman
Unfortunately, the data are out of our control. However, this solution
looks like it will do the job.

Thanks!

Greg--

On Mon, Jun 6, 2016 at 5:54 PM, Mike Bayer  wrote:

>
>
> On 06/06/2016 11:21 AM, Horcle wrote:
>
>> 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 = Column(String(255))
>> proc_code = Column(String(255))
>> proc_code_modifier = Column(String(255))
>> proc_code_system = Column(String(255))
>> result_value = Column(String(255))
>> result_value_num = Column(String(255))
>> result_value_num_orig = Column(String(255))
>> result_unit = Column(String(255))
>> result_unit_orig = Column(String(255))
>> ref_normal_min = Column(String(255))
>> ref_normal_max = Column(String(255))
>> result_characterization = Column(String(255))
>> collection_datetime = Column(DateTime)
>> result_datetime = Column(DateTime)
>> abnormal_flag = Column(String(255))
>> lab_status = Column(String(255))
>> result_comment = Column(UnicodeText)
>> component_comment = Column(UnicodeText)
>> order_id = Column(String(255))
>> order_num = Column(String(255))
>> order_priority = Column(String(255))
>> order_result_id = Column(String(255))
>> order_reviewed = Column(String(255))
>> order_type_orig = Column(String(255))
>> order_type_orig_id = Column(String(255))
>> result_code_orig = Column(String(255))
>> result_code_orig_system = Column(String(255))
>> result_status = Column(String(255))
>> patient_id = Column(Integer, ForeignKey('cp_patient.patient_id'))
>> service_id = Column(Integer, ForeignKey('cp_service.service_id'))
>> provider_id = Column(Integer, ForeignKey('cp_provider.provider_id'))
>>
>> and,
>>
>> class Provider(Model):
>> __tablename__ = 'cp_provider'
>> provider_id = Column(Integer, primary_key=True)
>> authorize_meds_yn = Column(String(80))
>> active_status = Column(String(80))
>> authorize_orders_yn = Column(String(80))
>> birth_date = Column(DateTime)
>> clinician_degree = Column(String(80))
>> clinician_title = Column(String(80))
>> country = Column(String(80))
>> dea_number = Column(String(80))
>> email = Column(String(80))
>> external_name = Column(String(80))
>> provider_e_prescribe_yn = Column(String(80))
>> inpatient_ordering_yn = Column(String(80))
>> name = Column(String(80))
>> npi = Column(String(80))
>> office_fax = Column(String(80))
>> office_phone = Column(String(80))
>> outpatient_ordering_yn = Column(String(80))
>> provider_type = Column(String(80))
>> referral_source_type = Column(String(80))
>> resident_yn = Column(String(80))
>> sex = Column(String(80))
>> surgical_pool_yn = Column(String(80))
>> transcription_user_yn = Column(String(80))
>> upin = Column(String(80))
>> encounter = relationship("EncounterList", backref=backref("Provider"),
>> lazy='dynamic')
>>
>> Where one provider can have multiple LabResults... How do I handle the
>> case when there may be a provider_id in the LabResult table, but not in
>> the Provider table (we are only keeping a subset of the provider list)?
>> I need to access the object Provider so that I can have access to all of
>> its attributes, such as Provider.name, etc. When I try this now, I get
>> an error that "Nonetype has attribute name." Ia there a way to set a
>> default value for when the result is NULL?
>>
>
> In relational database design, provider_id always must refer to a row in
> Provider.  If that's not the case, then your database is failing
> referential integrity and is mis-designed; the definition of a ForeignKey
> is that it's a constraint that indicates a remote primary key that must
> exist.
>
> If you're in some situation where this isn't actually happening and you
> need to work around it, it looks like you're just looking for a string
> "missing" instead of None?  This is just a Python access issue.   Use a
> method like "def get_provider_id()", or a synonym:
>
> class LabResult(Base):
>
> provider_id = Column(Integer)
>
> @synonym_for("_provider_id", map_column=True)
> @property
> def provider_id(self):
>return self._provider_id or "Missing"
>
>
>
>
>
>
>
>> Thanks!
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send
>> an email to sqlalchemy+unsubscr...@googlegroups.com
>> .
>> To post to this group, send email to sqlalchemy@googlegroups.com
>> .
>> Visit this group at https://groups.google.com/group/sqlalchemy.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "sqlalchemy" group.
> To 

Re: [sqlalchemy] Re: Dynamically constructing joins

2015-03-25 Thread Greg Silverman
Ha! Ha! On my previous attempts, I had something similar to this, but
instead, I had

query = db.session.query(label('sid',
 distinct(a[1].c.patient_sid)))

if (n  1):
for table in join_tables[1:]:
for criterion in join_criteria[1:]:
query = query.join(eval(table), eval(criterion))

Where the variables table and criterion were built lists, so that I ended
up doing a Cartesian product of all my tables, which was giving me many
problems, with aliasing being the least of it!

Thanks!

Greg--

On Tue, Mar 24, 2015 at 11:22 PM, Jonathan Vanasco jonat...@findmeon.com
wrote:

 any reason why you're not building a query like this?

query = db.session.query(label('sid',
  distinct(a[1].c.patient_sid)))
if n = 2
   query = query.\
 join(a[2],a[2].c.patient_sid==a[1].c.patient_sid)
if n = 3
   query = query.\
 join(a[3],a[3].c.patient_sid==a[1].c.patient_sid)

 or

query = db.session.query(label('sid',
  distinct(a[1].c.patient_sid)))
for i in range(2, n):
   query = query.\
 join(a[i],a[i].c.patient_sid==a[1].c.patient_sid)


  --
 You received this message because you are subscribed to a topic in the
 Google Groups sqlalchemy group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/sqlalchemy/SySyi4CCCUY/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to
 sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.




-- 
Greg M. Silverman
Senior Developer Analyst
Cardiovascular Informatics http://www.med.umn.edu/cardiology/
University of Minnesota
612-626-0919
g...@umn.edu

 ›  flora-script http://flora-script.grenzi.org/ ‹
 ›  grenzi.org  ‹
 ›  evaluate-it.org  ‹

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Issue with return results

2014-09-08 Thread Greg Silverman
Hi Jonathan,
For the record, in my current setup, I installed python via Homebrew. Prior
to that, I was using the Apple build of python, which would have been the
32-bit version that came with Lion.

Greg--

On Mon, Sep 8, 2014 at 6:31 PM, Jonathan Vanasco jonat...@findmeon.com
wrote:

 Looking at that issue, and suggested fix... I think you're best going with
 that route.  the stock apple Python is usually pretty bad, and it seems to
 be the compile settings apple selected, not python.  apple's version is
 often VERY out of date and has some weird settings.   It's screwed me and
 colleagues up a lot. I'd strongly suggest you do the following:

 1. Install a second, custom python [ you can get one from Python.org in a
 click-installer https://www.python.org/download/mac ].  You can then
 update your bash so that your console user will use that python, and not
 break anything on your mac.

 2. reinstall all pyodbc and everything else into that custom python's
 site-packages.  you actually need to do all this stuff whenever you have a
 version bump (2.7.7 to 2.7.8), but some packages magically work even if you
 don't.

 i've found that shit just works when you use a python.org interpreter.


 On Monday, September 8, 2014 7:04:17 PM UTC-4, Horcle wrote:

 Unfortunately, dumping SQL Server (in favor of Oracle) may not be an
 option, due to management concerns and other factors. Still working on it.

 However, I did manage to get this working with pymssql. Apparently, there
 is a bug with pyodbc and 64-bit python (see https://community.
 vertica.com/vertica/topics/mac_pyodbc_string_encoding_issue). So, short
 of applying the fix to the cpp file recompiling pyodbc (see
 http://www.vertica-forums.com/viewtopic.php?f=35t=1863p=6174#p6174),
 the easy solution is to use pymssql. I believe the upgrade I did from Lion
 to Mavericks allows use of 64-bit python now, so this makes sense.

 Thanks!

  --
 You received this message because you are subscribed to a topic in the
 Google Groups sqlalchemy group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/sqlalchemy/-i4-GQpXkzY/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to
 sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Issue with return results

2014-09-04 Thread Greg Silverman
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--


On Thu, Sep 4, 2014 at 8:31 PM, Horcle g...@umn.edu wrote:

 Thanks. I forgot to mention that I had tried adding the encoding scheme to
 freetds.conf. I also tried other encoding schemes, all to no avail. I may
 try pymssql tomorrow to see what that does. I would have tried mxodbc, but
 I am not about to pay $379 for a driver. I may also see if I can get the MS
 ODBC driver for Linux to work on my Mac.

 I have to say that the MS SQL stuff is a royal PITA, but unfortunately,
 that is what I am stuck with at work. Uggh. (;_;)

 The version of FreeTDS I have been using has always been 9.1 (although, I
 noticed that the Brew formula for it changed in the last few days to 9.1_1,
 for what that's worth).

 Greg--

 On Thursday, September 4, 2014 5:23:02 PM UTC-5, Michael Bayer wrote:

 SQL Server and unix, many things can change:

 - UnixODBC version
 - FreeTDS version  (0.82 and 0.91 have *extremely* different behaviors)
 - FreeTDS configuration

 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 wrote:

 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 sqlalchemy.engine.reflection import Inspector

 def connect():
 return pyodbc.connect(
 'DRIVER={FreeTDS};SERVER=server.ip.address;'
 'DATABASE=STUDY_PARTICIPANT;UID=test;PWD=test;port=1433;CHARSET=utf8;'
 'TDS_Version=9.1;')
 engine = sqlalchemy.create_engine('mssql+pyodbc://', creator=connect,
 encoding='latin1',echo='debug',supports_unicode_binds=False)
 conn = engine.connect()
 print conn

 for row in engine.execute('select 6 * 7 as [Result];'):
 print row.Result

 insp = reflection.Inspector.from_engine(engine)
 table_name = 'irb_desc'
 table_names = insp.get_table_names()
 if table_name not in table_names:
 print 'A: ' + table_name

 I used to get the following nice output:

 python test_connect.py
 2014-08-18 16:15:06,611 INFO sqlalchemy.engine.base.Engine
SELECT default_schema_name FROM
sys.database_principals
WHERE principal_id=database_principal_id()

 2014-08-18 16:15:06,611 INFO sqlalchemy.engine.base.Engine ()
 2014-08-18 16:15:06,613 DEBUG sqlalchemy.engine.base.Engine Col (
 'default_schema_name',)
 2014-08-18 16:15:06,614 DEBUG sqlalchemy.engine.base.Engine Row (u'dbo',
 )
 2014-08-18 16:15:06,616 INFO sqlalchemy.engine.base.Engine SELECT CAST('test
 plain returns' AS VARCHAR(60)) AS anon_1
 2014-08-18 16:15:06,616 INFO sqlalchemy.engine.base.Engine ()
 2014-08-18 16:15:06,619 INFO sqlalchemy.engine.base.Engine SELECT CAST('test
 unicode returns' AS NVARCHAR(60)) AS anon_1
 2014-08-18 16:15:06,619 INFO sqlalchemy.engine.base.Engine ()
 sqlalchemy.engine.base.Connection object at 0x101877ed0
 2014-08-18 16:15:06,639 INFO sqlalchemy.engine.base.Engine select 6 * 7
 as [Result];
 2014-08-18 16:15:06,639 INFO sqlalchemy.engine.base.Engine ()
 2014-08-18 16:15:06,641 DEBUG sqlalchemy.engine.base.Engine Col ('Result'
 ,)
 2014-08-18 16:15:06,641 DEBUG sqlalchemy.engine.base.Engine Row (42, )
 42
 2014-08-18 16:15:06,647 INFO sqlalchemy.engine.base.Engine SELECT [
 TABLES_1].[TABLE_NAME]
 FROM [INFORMATION_SCHEMA].[TABLES] AS [TABLES_1]WHERE [TABLES_1].[
 TABLE_SCHEMA] = CAST(? AS NVARCHAR(max)) AND [TABLES_1].[TABLE_TYPE] = ?
 ORDER BY [TABLES_1].[TABLE_NAME]
 2014-08-18 16:15:06,647 INFO sqlalchemy.engine.base.Engine ('dbo', 'BASE
 TABLE')
 2014-08-18 16:15:06,663 DEBUG sqlalchemy.engine.base.Engine Col (
 'TABLE_NAME',)
 2014-08-18 16:15:06,663 DEBUG sqlalchemy.engine.base.Engine Row (u
 'irb_desc', )
 2014-08-18 16:15:06,663 DEBUG sqlalchemy.engine.base.Engine Row (u'irbd',
 )
 2014-08-18 16:15:06,663 DEBUG sqlalchemy.engine.base.Engine Row (u
 'study_desc', )
 2014-08-18 16:15:06,664 DEBUG sqlalchemy.engine.base.Engine Row (u
 'study_irb', )
 2014-08-18 16:15:06,664 DEBUG sqlalchemy.engine.base.Engine Row span
 style=color: #660; class=st

 ...

  --
 You received this message because you are subscribed to a topic in the
 Google Groups sqlalchemy group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/sqlalchemy/-i4-GQpXkzY/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to
 sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.




-- 
Greg M. Silverman
Senior Developer Analyst
Cardiovascular Informatics http://www.med.umn.edu/cardiology/

Re: [sqlalchemy] cannot access tables

2014-08-18 Thread Greg Silverman
  SELECT default_schema_name FROM
sys.database_principals
WHERE name = ?
AND type = 'S'


On Mon, Aug 18, 2014 at 9:47 AM, Horcle g...@umn.edu wrote:

 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 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 sqlalchemy.engine import reflection
 from sqlalchemy.engine.reflection import Inspector

 def connect():
 return pyodbc.connect(
 'DRIVER={FreeTDS};SERVER=ip_address;'
  'DATABASE=db_name;UID=test;PWD=test;port=1433;'
 'TDS_Version=9.1;')
 engine = sqlalchemy.create_engine('mssql://', creator=connect)
 conn = engine.connect()
 print conn

 for row in engine.execute('select 6 * 7 as [Result];'):
 print row.Result

 insp = reflection.Inspector.from_engine(engine)
 table_name = 'irb_desc'
 table_names = insp.get_table_names()
 if table_name not in table_names:
 print 'A'

 Again, I am connecting fine with the database create.engine method (that
 is '42' is printing as expected), but when I run the
 inspector.get_table_names method with the given conditional it is printing
 the 'A' (I have tried other table names in the same database to which I
 added 'irbd_balance,' all with the same result.



 what is the SQL output if you set echo=‘debug’;   then, take the SQL you
 see and take a look at what it’s SELECTing so you can see what might be
 wrong.  Probably some schema name setting or something like that.



 Thanks, I did not realize this was an option (actually, it is echo=True,
 but at least I can see the SQL being sent). Hopefully this will lead me to
 an answer.

 Greg--

 --
 You received this message because you are subscribed to a topic in the
 Google Groups sqlalchemy group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/sqlalchemy/YSjU_Ohsyvw/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to
 sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.




-- 
Greg M. Silverman
Senior Developer Analyst
Cardiovascular Informatics http://www.med.umn.edu/cardiology/
University of Minnesota
612-626-0919
g...@umn.edu

 ›  flora-script http://flora-script.grenzi.org/ ‹
 ›  grenzi.org  ‹

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.