And that can be simplified to:
print(session.query()
             .with_entities(Jobmst.jobmst_type, Jobmst.jobmst_name)
             .first()
      )

On Friday, 9 February 2018 12:21:37 UTC, Jeremy Flowers wrote:
>
> Hi Simon.
> Instead of using values(), I did this.
> print(session.query(Jobmst)
>              .with_entities(Jobmst.jobmst_type, Jobmst.jobmst_name)
>              .first()
>       )
>
> and that worked a treat too. 
> Thanks.
>
>
> On Friday, 9 February 2018 11:58:18 UTC, Simon King wrote:
>>
>> The chaining-friendly method you are looking for is probably 
>> with_entities(): 
>>
>>
>> http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.with_entities
>>  
>>
>> Simon 
>>
>> On Fri, Feb 9, 2018 at 11:52 AM, Jeremy Flowers 
>> <jeremy.g...@gmail.com> wrote: 
>> > From watching your videos I always thought some sort of query object 
>> would 
>> > be returned from the query() operation, so method chaining (aka fluent 
>> > interface) could always be performed.. in a way that is analogous to 
>> JQuery. 
>> > But what I'm doing seems to be breaking that paradigm. What am I doing 
>> wrong 
>> > or not getting? 
>> > 
>> > On Thursday, 8 February 2018 20:29:45 UTC, Jeremy Flowers wrote: 
>> >> 
>> >> I've seen you can do things like this: 
>> >> fields = ['jobmst_type', 'jobmst_name'] 
>> >>  print(session.query(Jobmst).options(load_only(*fields)).first()) 
>> >> 
>> >> But according to the documentation, you should be able to do something 
>> >> with Query values() too. 
>> >> But once again I seem to be dumbfounded by the syntatic sugar. 
>> >> 
>> >> What data type does the list of values need? 
>> >> Is there a way to introspect that ahead of time? 
>> >> 
>> >> Thought I was onto something with .base_columns, but that didn't work 
>> >> either... 
>> >> 
>> >> I ended up with something like an instrumentalAttributes mismatch. 
>> >> print(session.query(Jobmst) 
>> >>              .values([Jobmst.jobmst_type.base_columns, 
>> >>                       Jobmst.jobmst_name.base_columns 
>> >>                       ]) 
>> >>              .first() 
>> >>       ) 
>> >> 
>> >> sqlalchemy.exc.InvalidRequestError: SQL expression, column, or mapped 
>> >> entity expected - got '[{Column('jobmst_type', Numeric(scale=0, 
>> >> asdecimal=False), table=<jobmst>, nullable=False)}, 
>> {Column('jobmst_name', 
>> >> String(length=256), table=<jobmst>, nullable=False)}]' 
>> >> 
>> >> BTW: I'm aware of querying with things like query(Jobmst.jobmst_type, 
>> >> Jobmst.jobmst_name) too - but looking to understand what values 
>> expects. 
>> >> Mike, Can documentation not specify type? 
>> > 
>> > -- 
>> > 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+...@googlegroups.com. 
>> > To post to this group, send email to sqlal...@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 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.

Reply via email to