question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.switch() and .join_from() for CTE's

See original GitHub issue

It looks to me like the .switch() and .join_from() methods are only defined on the ModelSelect class, meaning it’s impossible to join from a CTE to multiple other tables. It might be good to move the join context stuff up the class hierarchy to Select, unless there’s some reason doing so would be tricky.

Is there a workaround for this? I could join starting from one of the other tables, but I think that can have bad performance implications. Maybe making a new CTE for each join would work.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
coleifercommented, Jul 21, 2020

The join context only really has meaning for model-select, where peewee utilizes the structure of the model relationships to infer predicates and other things. A CTE can join multiple times, you just need to specify the appropriate predicate in the on= clause.

0reactions
BigPicturescommented, Jul 22, 2020

It’s okay, I got my thing working. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Relationships and Joins — peewee 3.15.4 documentation
Note the call to switch() - that instructs Peewee to set the join context back ... CTE. .join_from(Tweet, User) # Join from tweet...
Read more >
SQL Switch/Case in 'where' clause - Stack Overflow
I want the condition to exit because var IS equal to 0, but it goes ahead to check if it is numeric, which...
Read more >
Subquery vs. CTE: A SQL Primer - LearnSQL.com
We've done this by using a subquery inside the FROM clause. Then, we simply use MAX() to return the largest average length. These...
Read more >
Simplify your SQL Queries with Common Table Expressions ...
Simplify your SQL Queries with Common Table Expressions (CTEs) ... A CTE is a query whose result set you can reference in a...
Read more >
CTEs in SQL Server; Querying Common Table Expressions
This article gives overview of a convenient way to query data Common Table Expressions(CTE) in SQL Server.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found