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

"CTE" extension to the .md spec #30

Open
natb1 opened this issue Feb 29, 2024 · 2 comments
Open

"CTE" extension to the .md spec #30

natb1 opened this issue Feb 29, 2024 · 2 comments

Comments

@natb1
Copy link

natb1 commented Feb 29, 2024

The .md spec used in the repo and described here https://github.com/OHDSI/QueryLibrary/blob/master/vignettes/UsingQueryLibrary.Rmd is straight forward and enables a lot of use cases. I think a small extension to the spec that allowed for a query to define "CTEs" (SQL 'with' clauses) would make it possible to use the .md to document even very complex queries such as the ones described in #29 . If this is within the vision for this repo then I could draft an extension to support CTEs that uses the existing anchor tags in the .md to allow for simple navigation of the .md on github.

@natb1 natb1 changed the title "CTE" extension of the .md spec "CTE" extension to the .md spec Feb 29, 2024
@natb1
Copy link
Author

natb1 commented Mar 5, 2024

Common Table Expressions (CTE)

The CTE section of the QueryLibrary markdown documents
allow queries to reference common subqueries. This
way, even very complex queries can be represented
in the query library:

  • Large queries can be decomposed into smaller queries.
  • Queries that rely on features that vary between dialects
    can be isolated into subqueries.

CTEs are a markdown list of markdown anchor tags ("links").
The text of the anchor is the SQL alias used in the query
and the anchor refers to the URL of any other
QueryLibrary document.

@natb1
Copy link
Author

natb1 commented Mar 5, 2024

SELECT count(*) as person_count FROM person

-- CTEs can be used to decompose queries.
INNER JOIN female USING gender_concept_id

-- Or, to isolate logic from different dialects.
JOIN age USING person_id
WHERE age > 18
- [female](raw.github.com/.../female.md)
- [age](raw.github.com/.../ansi/age.md)
- [age](raw.github.com/.../sqlserver/age.md)

raw.github.com/.../female.md

Query

SELECT concept_id AS gender_concept_id FROM concept WHERE concept_id = 8532

...etc.

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

No branches or pull requests

1 participant