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

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

2016-06-06 Thread Mike Bayer
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))

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

2016-06-06 Thread Horcle
I would ultimately like to do something like: provider_id = Column(Integer, func.coalesce(ForeignKey('cp_provider.provider_id'), 'Missing'), nullable=True) but this is not working... I also tried using coalesce with a primaryjoin condition on encounter = relationship("EncounterList",

[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 > definition for

[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_svc_lab_result'

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 wrote: >> >> there's no

[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

[sqlalchemy] How to insert using subquery that return multiple fields?

2016-06-06 Thread Kawing Chiu
I'm trying to implement the common "insert if not exists" pattern using sqlalchemy, but after a day of googling can't find out how to do it: My query is like (sqlite backend): INSERT INTO memos(id,text) SELECT 5, 'text to insert' WHERE NOT EXISTS(SELECT 1 FROM memos WHERE id = 5 AND text =