Use SQLView for a reusable, named SQL query that other queries reference as a virtual table source, analogous to a SQL view. An SQLView is a near-twin of SQLQuery: it bundles SQL and its dependencies for sharing and versioning, but it is identified by its canonical URL so that other SQLQueries and SQLViews can build upon it.
The key differences from SQLQuery are:
- The Library
typeis fixed toLibraryTypesCodes#sql-view. - An SQLView SHALL NOT declare parameters. Dependent views cannot be parameterised in this iteration of the specification.
SQLView does not define table schemas, data extraction, execution behaviour, or APIs; those belong to ViewDefinition and its operations. An SQLView references ViewDefinitions and other SQLViews; execution environments resolve these to physical or virtual tables.
Use relatedArtifact with type = "depends-on" to list the ViewDefinitions and
SQLViews this view builds upon. Each resource is the canonical URL of a
ViewDefinition or another SQLView, and each label defines the table name used
in the SQL.
"relatedArtifact": [
{ "type": "depends-on", "resource": "https://example.org/ViewDefinition/patient_view", "label": "patient_view" },
{ "type": "depends-on", "resource": "http://hl7.org/fhir/uv/sql-on-fhir/Library/ActivePatientsView", "label": "active_patients" }
]The allowed targets are recorded as a targetProfile on
relatedArtifact.resource (Canonical(ViewDefinition or SQLView)). Validators
enforce this whenever the canonical resolves to a known resource; for canonicals
that cannot be resolved the constraint is advisory.
Unlike SQLQuery, an SQLView SHALL NOT declare Library.parameter entries
(parameter is constrained to 0..0). A view is a fixed, reusable building
block; callers compose with it by referencing it from a parameterised SQLQuery.
Store the view's SQL in content exactly as for SQLQuery:
contentType starting with application/sql, the base64-encoded data element,
and an optional sql-text extension for
human readability. Dialect-specific variants follow the same selection rules as
SQLQuery.
Constraints:
- Library type SHALL be
LibraryTypesCodes#sql-view Library.parameterSHALL be absent- Every
content.contentTypeSHALL start withapplication/sql content.dataSHALL be present; thesql-textextension MAY carry a plain-text copy- Dependencies SHALL use
relatedArtifactwithtype = "depends-on", alabel, and aresourcereferencing a ViewDefinition or SQLView
For notes on query composition, see the Notes tab below.