From 7d6df6d3288f64d2e21ec21b9b8fa04d38646ed2 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki <7413593+a8m@users.noreply.github.com> Date: Sun, 6 Aug 2023 23:02:37 +0300 Subject: [PATCH] doc: add view to hcl schema (#1935) --- doc/md/atlas-schema/hcl.mdx | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/doc/md/atlas-schema/hcl.mdx b/doc/md/atlas-schema/hcl.mdx index 46230a70344..089980b985d 100644 --- a/doc/md/atlas-schema/hcl.mdx +++ b/doc/md/atlas-schema/hcl.mdx @@ -207,6 +207,43 @@ table "b" "users" { } ``` +## View + +A `view` is a virtual table in the database, defined by a statement that queries rows from one or more existing +tables or views. + +```hcl +view "clean_users" { + schema = schema.public + column "id" { + type = int + } + column "name" { + type = text + } + as = <<-SQL + SELECT u.id, u.name + FROM ${table.users.name} AS u + JOIN ${view.active_users.name} AS au USING (id) + SQL + depends_on = [table.users, view.t1] + comment = "A view to active users without sensitive data" +} + +view "comedies" { + schema = schema.public + column "id" { + type = int + } + column "name" { + type = text + } + as = "SELECT id, name FROM films WHERE kind = 'Comedy'" + depends_on = [table.films] + check_option = CASCADED +} +``` + ## Column A `column` is a child resource of a `table`.