Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Composable SQL queries #632

Open
inhaledesign opened this issue Oct 28, 2024 · 3 comments
Open

[Request] Composable SQL queries #632

inhaledesign opened this issue Oct 28, 2024 · 3 comments

Comments

@inhaledesign
Copy link

inhaledesign commented Oct 28, 2024

Is your feature request related to a problem? Please describe.
In my organization, we have a database where we can't use SQL views or procedures (security reasons). We're trying to work around this by coming up with a way to compose together strings of SQL in our Java code. This would allow us to define, say, a SELECT statement in one place, test it, and then use it as a CTE in other places.

Describe the solution you'd like
If Manifold could allow something along these lines, it would address our issue:

        final String inneryQuery = "SELECT PERSON_COL FROM MYSCHEMA.PERSON";
        "[MyQuery.sql/] SELECT * FROM ( :inneryQuery )".fetchOne();
@rsmckinney
Copy link
Member

Interesting, manifold-sql also supports files as SQL resources.

src/main/resources/org/example/queries/Persons.sql

SELECT PERSON_COL FROM MYSCHEMA.PERSON
import org.example.queries.Persons;
. . .
"[MyQuery.sql/] SELECT * FROM (::Persons)".fetchOne();

Where the ::Persons syntax is imaginary. But the idea is to allow type-safely inlining other manifold queries. Of course, the Persons query wouldn't have to be in a file, it could be a local inline query as well.

This syntax would work anywhere a select could be used, including the WITH clause.

"""
[CteExample.sql] WITH my_cte (alpha, beta, gamma) AS (::MyQuery), 
  SELECT * FROM my_cte . . . 
""".fetch(. . .)

Warning, I haven't thought this through, but I think it's doable. . . at least using the ::QueryType syntax with inlined queries.

@inhaledesign
Copy link
Author

@rsmckinney Just to be clear: the ::QueryType syntax does not currently exist in Manifold, but you think it could be added?

@rsmckinney
Copy link
Member

Correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants