Feature Request/Discussion: CTE Persistence Across SELECT Statements #1089
Replies: 2 comments
-
|
Hi! It looks like what you are looking for is temporary tables ! Have a look at https://sql-page.com/extensions-to-sql (Working with larger temporary results in particular) https://sql-page.com/blog.sql?post=Performance%20Guide (Reusing a large query result set) |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
thank you, this will do :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Hi, @lovasoa currently, CTEs (Common Table Expressions) defined in one SELECT statement don't persist to subsequent SELECT statements in the same SQLPage file. This leads to significant code duplication when the same CTE logic needs to be used across multiple components.
Current Behavior
Error:
error returned from database: (code: 1) no such table: api_dataCurrent Workarounds
1. Repeat the CTE in every query (verbose)
2. Use SET variables (limited to scalar values)
This works for simple values but doesn't help with:
Use Case: API Response Parsing
A common pattern in SQLPage is fetching JSON from an API and displaying it across multiple components:
Currently, we must either:
json_extract($api_response, '...')throughout (60+ calls)Proposed Solution
Allow CTEs to persist for the current file execution scope, similar to how SET variables work:
Benefits
Real-World Impact
In my current project, a single page has:
json_extract()calls + ~30 translation subqueriesThank you for considering this! SQLPage is an amazing tool, and I'm happy with the current workarounds, but I wanted to open this discussion in case others face the same challenge.
Environment:
Beta Was this translation helpful? Give feedback.
All reactions