Re: [sqlalchemy] Re: Trying to find a way to sort a query given the name of one of its columns

2023-06-12 Thread Mike Bayer



On Mon, Jun 12, 2023, at 3:12 AM, Lele Gaifax wrote:
> Lele Gaifax  writes:
>
>> I will study the contains_eager() alternative and try to modernize my
>> code that still uses that idiom.
>
> After reading the different sections (narrative and reference), I wonder
> if there is a case where the joinedload() has some advantage over
> contains_eager(), or if the former, being "the oldest style of eager
> loading in SA ORM" is kept mainly for backward compatibility.

joinedload() is a lot easier to use for sure and yes there are probably some 
very nested/ crazyish cases where joinedload "works" and contains_eager either 
doesnt quite work or is very difficult to make it work.


>
> bye, lele.
> -- 
> nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
> real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
> l...@metapensiero.it  | -- Fortunato Depero, 1929.
>
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/87r0qh9mrs.fsf%40metapensiero.it.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/cc58ebb7-6489-4e05-8d21-18bd68b91933%40app.fastmail.com.


[sqlalchemy] Re: Trying to find a way to sort a query given the name of one of its columns

2023-06-12 Thread Lele Gaifax
Lele Gaifax  writes:

> I will study the contains_eager() alternative and try to modernize my
> code that still uses that idiom.

After reading the different sections (narrative and reference), I wonder
if there is a case where the joinedload() has some advantage over
contains_eager(), or if the former, being "the oldest style of eager
loading in SA ORM" is kept mainly for backward compatibility.

bye, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/87r0qh9mrs.fsf%40metapensiero.it.


[sqlalchemy] Re: Trying to find a way to sort a query given the name of one of its columns

2023-06-12 Thread Lele Gaifax
Federico Caselli  writes:

> Also you may not need the col_by_name at all for order_by, since you can 
> pass the string in order_by directly: 
> https://docs.sqlalchemy.org/en/20/tutorial/data_select.html#tutorial-order-by-label
> This case is still not supported, since doing "query.order_by('firstname')" 
> raises "column not found".

Yes, but in rare cases I exploited its ability of findind a column not
"exposed" in the select, belonging to one of the joined tables, for
example to have a stable sort.

> (ps: github discussions should be preferred to share code snippets)

Sorry, note taken.

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/87v8ft9ny3.fsf%40metapensiero.it.


[sqlalchemy] Re: Trying to find a way to sort a query given the name of one of its columns

2023-06-11 Thread Federico Caselli
Also you may not need the col_by_name at all for order_by, since you can 
pass the string in order_by directly: 
https://docs.sqlalchemy.org/en/20/tutorial/data_select.html#tutorial-order-by-label
This case is still not supported, since doing "query.order_by('firstname')" 
raises "column not found".

(ps: github discussions should be preferred to share code snippets)

On Saturday, 10 June 2023 at 21:05:35 UTC+2 Lele Gaifax wrote:

> "Mike Bayer"  writes:
>
> > it looks like you're trying to add an ORDER BY to the table that's
> > only there via joinedload(). That's *really* not something we
> > anticipate and it would be better if people proposed perhaps ad-hoc
> > order_by expressions to be added to common loader options like
> > joinedload() and selectinload(), in the same way that we offer ad-hoc
> > WHERE criteria for these options now. as you are probably aware, the
> > current way to do "joinedload with custom criteria / ordering / etc"
> > is to write the query using outerjoin() and order_by() normally, then
> > use contains_eager().
>
> Oh, thanks a lot for this!. Accordingly with the git history, I
> introduced that test to address a deprecation warning issued by SA 1.4+
> load_only()...
>
> I will study the contains_eager() alternative and try to modernize my
> code that still uses that idiom.
>
> bye, lele.
> -- 
> nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
> real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
> le...@metapensiero.it | -- Fortunato Depero, 1929.
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/07785e0a-27e3-4977-857a-34cda38903f8n%40googlegroups.com.


[sqlalchemy] Re: Trying to find a way to sort a query given the name of one of its columns

2023-06-10 Thread Lele Gaifax
"Mike Bayer"  writes:

> it looks like you're trying to add an ORDER BY to the table that's
> only there via joinedload(). That's *really* not something we
> anticipate and it would be better if people proposed perhaps ad-hoc
> order_by expressions to be added to common loader options like
> joinedload() and selectinload(), in the same way that we offer ad-hoc
> WHERE criteria for these options now. as you are probably aware, the
> current way to do "joinedload with custom criteria / ordering / etc"
> is to write the query using outerjoin() and order_by() normally, then
> use contains_eager().

Oh, thanks a lot for this!. Accordingly with the git history, I
introduced that test to address a deprecation warning issued by SA 1.4+
load_only()...

I will study the contains_eager() alternative and try to modernize my
code that still uses that idiom.

bye, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/87zg576sun.fsf%40metapensiero.it.