Reusable queries, first step - in CTEs#174
Merged
jongleb merged 1 commit intoygrek:masterfrom Apr 25, 2025
Merged
Conversation
77ce54d to
a570922
Compare
e1609bc to
ccedd90
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a possibility to reuse queries, at the current step with only CTE syntax.
Syntax:
Before the query as usual after a name you can specify a kind of it inclusion
Generate a query that can only be reused
OR
Generate a query that can be reused and be executable
Keep a query as usual or specify explicitly to have it only as executable
Let's take a look at the example from tests
We write the following queries (in the same file, in the proper order, so that the query that was declared below is clearly accessible to the one declared above)
this way, we say that the first one is available as only a reusable query, which means that the it doesn't have self function in the generated code. And will be substituted in place of its use (&abcd) in this case. that is, in order to substitute this query (in the current implementation, embedding is only available as cte) you need to specify & and its name together.
Usage of parameters
The use of all parameter types as seen in the example in functions for reuse is also available as for regular ones, the type inference of parameters will be unified further
In result the following function will be generated
it works similarly for reusable and simultaneously executable ones, the only difference being that for such requests both a function and a substitution are generated, for only executable ones nothing changes